【问题标题】:File uploading is not working on live server文件上传在实时服务器上不起作用
【发布时间】:2017-02-10 12:49:46
【问题描述】:

警告:move_uploaded_file(/images/24_silver_2_1.jpg):打开失败 流:中没有这样的文件或目录 C:\Inetpub\vhosts\leojungen.com\httpdocs\launch-complaint.php 上线 72

警告:move_uploaded_file():无法移动 'C:\Windows\Temp\php19A2.tmp' 到 '/images/24_silver_2_1.jpg' 中 C:\Inetpub\vhosts\leojungen.com\httpdocs\launch-complaint.php 上线 72

function uploadMultipleFiles($complaintId){
    global $_pdo;$path = '';
    // Count # of uploaded files in array
    $total = count($_FILES['files']['name']);
    // Loop through each file
    for($i=0; $i<$total; $i++) {
        //Get the temp file path
        $tmpFilePath = $_FILES['files']['tmp_name'][$i];
        //Make sure we have a filepath
        if ($tmpFilePath != ""){
            //Setup our new file path
            $newFilePath = "/images/".$complaintId."_".$_FILES['files']['name'][$i];
            //Upload the file into the temp dir
            //echo "path: "; print_r($_SERVER);exit;
            move_uploaded_file($tmpFilePath,$newFilePath);
        }
        $path .= $complaintId."_".$_FILES['files']['name'][$i]."^";
    }
}

在我的本地环境中,所有文件都可以正常工作,但是当我将其实时部署时,它无法正常工作。

【问题讨论】:

    标签: php file-upload cpanel plesk


    【解决方案1】:

    这是因为目录/images 不存在于服务器上,或者该目录上的write permission 丢失。检查并修复此问题,然后重试。

    【讨论】:

    • 是的,它说,警告:move_uploaded_file(images/26_grey_2.jpg):打开流失败:C:\Inetpub\vhosts\leojungen.com\httpdocs\launch-complaint.php 中的权限被拒绝第 72 行警告:move_uploaded_file(): Unable to move 'C:\Windows\Temp\php3891.tmp' to 'images/26_grey_2.jpg' in C:\Inetpub\vhosts\leojungen.com\httpdocs\launch-complaint.php在第 72 行
    【解决方案2】:
    $newFilePath = "/images/".$complaintId."_".$_FILES['files']['name'][$i];
    

    把这个改成

    $newFilePath = "images/".$complaintId."_".$_FILES['files']['name'][$i];
    

    【讨论】:

    • 做到了,它现在给出了权限问题,警告:move_uploaded_file(images/26_grey_2.jpg):无法打开流:C:\Inetpub\vhosts\leojungen.com\httpdocs\launch 中的权限被拒绝-complaint.php 在第 72 行警告:move_uploaded_file():无法将 'C:\Windows\Temp\php3891.tmp' 移动到 C:\Inetpub\vhosts\leojungen.com\httpdocs\ 中的 'images/26_grey_2.jpg'第 72 行的 launch-complaint.php
    • 确保您对该文件夹有写权限。
    【解决方案3】:

    而不是: $newFilePath = "/images/".$complaintId."_".$_FILES['files']['name'][$i];

    请尝试以下方法:

    $newFilePath = "./images".$complaintId."_".$_FILES['files']['name'][$i];

    ./images 中的句点表示 root/images....如果在 root 和 images 之间还有其他内容..包括它

    我知道这是一个非常老的问题,但我发布了这个答案,以便如果有像我这样的新程序员来......他会得到适合我的解决方案

    【讨论】:

      猜你喜欢
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      相关资源
      最近更新 更多