【问题标题】:move_uploaded_file() failed to open stream and move_uploaded_file(): Unable to movemove_uploaded_file() 无法打开流和 move_uploaded_file():无法移动
【发布时间】:2019-02-23 14:19:47
【问题描述】:

我正在做一个文件上传页面,它会在添加文件之前重命名文件,我收到了这些错误。 我已经在网站的文件夹中尝试了chmod -R 777 ./,但它仍然不起作用。

 $dir = Users::currentUser()->id;//each user have his folder
if(move_uploaded_file($_FILES["file"]["tmp_name"], PROOT . 'files' . DS . $dir . DS))
    {
      echo "The file has been uploaded as ".$ran2.$ext;
        //Router::redirect('upload');
    }
    else
    {
      echo "Sorry, there was a problem uploading your file.";
    }

PROOT 被我定义为网站根文件夹define('PROOT','/framework/');DS 是分隔符(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? define('DS', '/') : define('DS', DIRECTORY_SEPARATOR);

这就是错误的样子

Warning: move_uploaded_file(/framework/files/4/): failed to open stream: No such file or directory in /opt/lampp/htdocs/framework/app/controllers/UploadController.php on line 46


Warning: move_uploaded_file(): Unable to move '/opt/lampp/temp/phpHz70FG' to '/framework/files/4/' in /opt/lampp/htdocs/framework/app/controllers/UploadController.php on line 46

我也从if 语句中得到错误

Sorry, there was a problem uploading your file.

here 是我的文件结构的图片

更新

问题是 ubuntu 权限的原因,在 Windows 上它可以正常工作

【问题讨论】:

    标签: php apache chmod


    【解决方案1】:

    试试看

    define('PROOT','framework/');
    (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? define('DS', '/') : define('DS', DIRECTORY_SEPARATOR)
    
    $dir = Users::currentUser()->id;//each user have his folder
    $path = PROOT . 'files' . DS . $dir . DS;
    if(move_uploaded_file($_FILES["file"]["tmp_name"],$path)
        {
          echo "The file has been uploaded as ".$ran2.$ext;
            //Router::redirect('upload');
        }
        else
        {
          echo "Sorry, there was a problem uploading your file.";
        }
    

    【讨论】:

    • $path = PROOT 。 '文件' 。 DS 。 $目录。 DS;给 echo 路径变量你会得到什么
    【解决方案2】:

    你必须使用绝对路径 喜欢

     define('PROOT','/opt/lampp/htdocs/framework/');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 2011-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 2023-03-18
      相关资源
      最近更新 更多