文件上传在实时服务器上不起作用

File uploading is not working on live server

Warning: move_uploaded_file(/images/24_silver_2_1.jpg): failed to open stream: No such file or directory in C:\Inetpub\vhosts\leojungen.com\httpdocs\launch-complaint.php on line 72

Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php19A2.tmp' to '/images/24_silver_2_1.jpg' in C:\Inetpub\vhosts\leojungen.com\httpdocs\launch-complaint.php on line 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]."^";
    }
}

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

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

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

将此更改为

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

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

请尝试以下操作:

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

./images 中的句点表示 root/images..如果根和图像之间还有其他..包含它

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