【问题标题】:Can't Upload image using using php无法使用php上传图片
【发布时间】:2015-03-02 04:49:38
【问题描述】:

我无法上传图片。我在ubuntu中使用lampp服务器。它显示了一些我无法弄清楚的错误..

if (isset($_POST["submit"]))
 {
    $fileType = $_FILES["file"]["type"];

    if (($fileType == "image/gif") ||
            ($fileType == "image/jpeg") ||
            ($fileType == "image/jpg") ||
            ($fileType == "image/png")) {
        //Check if file exists
        if (file_exists("Images/Coffee/" . $_FILES["file"]["name"])) {
            echo "File already exists";
        } else {
            move_uploaded_file($_FILES["file"]["tmp_name"], "Images/Coffee/" . $_FILES["file"]["name"]);
            echo "Uploaded in " . "Images/Coffee/" . $_FILES["file"]["name"];
        }
    } }

我的错误是

警告:move_uploaded_file(Images/Coffee/costa.png):无法打开流:第 23 行 /opt/lampp/htdocs/newphp/uplaodimage.php 中的权限被拒绝

警告:move_uploaded_file(): Unable to move '/opt/lampp/temp/phpE2uIod' to 'Images/Coffee/costa.png' in /opt/lampp/htdocs/newphp/uplaodimage.php on line 23 在 Images/Coffee/costa.png 中上传

【问题讨论】:

  • 它在警告信息中很清楚。您需要在上传的路径中授予写入权限
  • 我该怎么做?请解释一下。谢谢

标签: php


【解决方案1】:

您在存储文件的目录中没有写入权限,因此您首先要向要上传文件的目录授予写入权限 就像在 Ubuntu 中一样:

chmod -R 777 /path..

【讨论】:

    【解决方案2】:
    bool is_writable ( string $filename_or_directory )
    

    会告诉你文件的目录是可写的

    【讨论】:

      猜你喜欢
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 2018-12-14
      • 2013-12-27
      • 2012-12-31
      • 2018-10-23
      • 2012-11-30
      相关资源
      最近更新 更多