【发布时间】:2014-04-22 15:08:11
【问题描述】:
我有这样的 PHP 代码:
<?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.';
}
}
}
?>
运行此代码时会出现以下消息:
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
这是怎么回事?
【问题讨论】:
-
看起来是文件夹权限问题。您可能需要
chmod具有正确写入权限的文件夹。 -
看来,你没有权限执行
chowm和chmod() -
看看相关问题 ------------------------------------------------ -------------------------------------------------- >
标签: php