Php chmod () does not change permissions

I am having problems loading an image script.

I know that there are hundreds of identical questions, but I have not found one that will work for me.

$upload_dir = "images/postcards/";
chmod($upload_dir, 777);
if (is_writable($upload_dir)) {
    echo 'The file is writable';
} else {
    echo 'The file is not writable';
}

This always returns that the file is "not writable"

I tried to install chmodon 0777and -rwxrwxrwx. But the result has always been the same. Any ideas?

+5
source share
4 answers

The directory must belong to the user invoking the script (usually www-data, apacheor httpdif you use the script in the apache / * NIX configuration). The user cannot set 777 rights to directories that he does not have.

See the note to chmod () manual :

- , PHP. , , FTP. , .

+9

PHP error_report, , , chmod:

ini_set('display_errors', true);
error_reporting(E_ALL);

, - , , WebServer .

+2

, :

<?php
$ftp_details['ftp_user_name'] = 'your ftp username';
$ftp_details['ftp_user_pass'] = 'your ftp password';
$ftp_details['ftp_root'] = '/public_html/';
$ftp_details['ftp_server'] = 'ftp' . $_SERVER['HTTP_HOST'];
function ftp_chmod($path, $mod, $ftp_details) {
  extract($ftp_details);
  $conn_id = ftp_connect($ftp_server);
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to chmod $path directory
  if (ftp_site($conn_id, 'CHMOD ' . $mod . ' ' . $ftp_root . $path) !== false) {
    $success = true;
  }
  else {
    $success = false;
  }

  ftp_close($conn_id);
  return $success;
}
?>

, , , . , .

0

chmod, apache: apache ( -). SELinux , , :

sudo setenforce 0

And chmod works. Now about how to make SELinux exception for this case ... (and don't forget to enable SELinux, of course)

0
source

All Articles