【问题标题】:i get the permissions denied error while uploading an image on the local xampp server在本地 xampp 服务器上上传图像时出现权限被拒绝错误
【发布时间】:2013-01-13 14:26:10
【问题描述】:

xampp 中的 htdocs 文件夹具有 777 权限,我可以在那里手动复制更改任何文件,但将文件上传到子文件夹会出错。我的代码是:

<?php
define ('MAX_FILE_SIZE', 1024 * 50);
if (array_key_exists('submit', $_POST)) {
// define constant for upload folder
define('UPLOAD_DIR', '/opt/lampp/htdocs/properties/');
// replace any spaces in original filename with underscores
$file = str_replace(' ', '_', $_FILES['image']['name']);
// create an array of permitted MIME types
$permitted = array('image/gif', 'image/jpeg', 'image/pjpeg','image/png');
// upload if file is OK
if (in_array($_FILES['image']['type'], $permitted)
  && $_FILES['image']['size'] > 0 
  && $_FILES['image']['size'] <= MAX_FILE_SIZE) {
switch($_FILES['image']['error']) {
  case 0:
    // check if a file of the same name has been uploaded
    if (!file_exists(UPLOAD_DIR . $file)) {
// move the file to the upload folder and rename it
$success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR $file);
} else {
$result = 'A file of the same name already exists.';
}
if ($success) {
$result = "$file uploaded successfully.";
} else {
$result = "Error uploading $file. Please try again.";
}
break;
case 3:
case 6:
case 7:
case 8:
$result = "Error uploading $file. Please try again.";
break;
case 4: 
$result = "You didn't select a file to be uploaded.";
}
} else {
$result = "$file is either too big or not an image.";
}
}
?>

我得到的错误是:

Warning: move_uploaded_file(/opt/lampp/htdocs/properties/Cover.jpg): failed to open stream: Permission denied in /opt/lampp/htdocs/listprop.php on line 82

【问题讨论】:

    标签: php upload


    【解决方案1】:

    检查是safe_modeon 在你的php.ini

    如果只有 xampp 文件夹可写但无济于事,那么您也需要子文件夹可写。

    其次,只是问

    define('UPLOAD_DIR', '/opt/lampp/htdocs/properties/');
    

    lampp 在哪里不应该是xampp?只是询问(这也可能导致移动问题)

    【讨论】:

    • lampp 是磁盘上的目录名称,这就是我安装它时的样子.. php.ini 中的 safe_mode 已关闭,并且 chmod 已应用于所有子文件夹以及htdocs 目录..
    • 另外,upload_tmp_dir 没有定义,错误显示它使用 tmp,所以我将 tmp 文件夹设置为 777 权限,但仍然没有运气
    • 你的 apache 日志是怎么说的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-16
    • 1970-01-01
    • 2020-12-28
    • 2018-05-22
    • 2020-05-24
    • 2014-09-29
    • 1970-01-01
    相关资源
    最近更新 更多