可以';t访问新服务器上上载的文件


Can't access file uploads on new server

我最近刚刚将本地MAMP安装转移到我的Ubuntu EC2服务器上,访问文件上传时遇到了麻烦。看起来一切都应该正常,但我不知道为什么不正常。我在php.ini中的最大上传量为5MB,这应该足够上传照片了,所以我知道不是这样。我还没有更改默认目录,但我想也许我应该在Apache虚拟主机上与其他两个域一起上传这个域?我不想在我的php脚本中走这条路:

ini_set('upload_tmp_dir','/your-home-www/tmp/');

但是如果虚拟主机处理文件是绝对必要的,则会。我很确定这不是我的代码,因为它在我的localhost MAMP安装上完美地工作,但如果有帮助的话,下面是处理照片的代码片段:

$fileTmpLoc = $photo["tmp_name"];
$fileSize = $photo["size"]; 
if (!$fileTmpLoc) { // if file not chosen
      sendResponse(404,"ERROR: Photo not sent.");
      exit;
} else if($fileSize > 5242880) { // if file size is larger than 5 Megabytes
      unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
      sendResponse(413, "ERROR: Your file was larger than 5 Megabytes in size.");
      exit;
} else {
$newName = "image01.jpg";
    $moveResult = copy($fileTmpLoc, "members/$id/".$newName);
    if ($moveResult != true) {
         @unlink($fileTmpLoc); 
         sendResponse(404,"ERROR: File not uploaded. Try again.");
         exit;
    }
 ....
}

现在,它一直到sendResponse(404,"错误:文件未上传。请重试。");,因此,也许它与tmp文件无关,但它仍然没有上传。用户的members目录和$id目录都设置为777,所以我根本不知道发生了什么

您必须使用标准的PHP函数

move_uploaded_file()

将上载的文件移动到其位置。