Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have PHP code like this:

<?php
ini_set('display_errors', true);
error_reporting(E_ALL);

$error = array();
if (isset($_POST['submit'])) {
    $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'upload';
    if (!empty($_FILES)) {
        $tmp = $_FILES['file']['tmp_name'];
        $file = $dir . DIRECTORY_SEPARATOR . $_FILES['file']['name'];
        if (is_uploaded_file($tmp)) {
            if (!chown($dir, 'nobody')) {
                $error[] = 'Owner tidak bisa di replace!';
            }
            if (!chmod($dir, intval(755, 8))) {
                $error[] = 'Direktori "' . $dir . '" tidak bisa diberi akses!';
            }
            if (!move_uploaded_file($tmp, $file)) {
                $error[] = 'Gagal memindahkan berkas "' . $file . '"';
            }
            if (file_exists($file)) {
                $error[] = 'Berhasil di unggah! ' . $file;
            }
        } else {
            $error[] = 'Berkas tidak bisa di unggah.';
        }
    }
}
?>

When running this code the following messages appear:

Warning: chown(): Operation not permitted in /var/www/html/jdih/upload.php on line 23

Warning: chmod(): Operation not permitted in /var/www/html/jdih/upload.php on line 24

Warning: move_uploaded_file(/var/www/html/jdih/upload/06-naiveBayes-example.pdf): failed to open stream: Permission denied in /var/www/html/jdih/upload.php on line 25

Warning: move_uploaded_file(): Unable to move '/tmp/phpMHL5CQ' to '/var/www/html/jdih/upload/06-naiveBayes-example.pdf' in /var/www/html/jdih/upload.php on line 25

What's going on here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
164 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should verify file permissions and file owner.

To change file permissions :

chmod -R 775 /var/www/html/jdih

And set the owner to the user who run your apache server.

chown www-data:www-data /var/www/html/jdih

Note : the owner depends on your distribution, on Ubuntu it's www-data, it could be httpd or http or something else.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...