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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…