dqwh1119 2012-08-31 21:13
浏览 32
已采纳

无法访问新服务器上的文件上载

I just recently moved my local MAMP installation to my live Ubuntu EC2 server and I'm having a devil of a time accessing file uploads. Everything looks like it should be working okay, but I don't know why it's not. I have a max upload of 5MB in in the php.ini, which should be plenty for uploading photos, so I know that's not it. Haven't changed the default directory, but thinking maybe I should as the domain's on an Apache virtual host with 2 other domains? I don't want to go this route in my php scripts:

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

but will, if it's absolutely necesary for the virtual host to process the files. I'm pretty sure it's not my code, as it works flawlessly on my localhost MAMP installation but here's the snippet of code that processes the photos if it helps:

$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;
    }
 ....
}

Now, it makes it all the way down to sendResponse(404,"ERROR: File not uploaded. Try again.");, so maybe it has nothing to do with the tmp file, but it is still not uploading. And the members directory and the $id directory for the user are both set to 777, so I literally have no clue what's going on. This is coming from an IOS client, not an html form

  • 写回答

1条回答 默认 最新

  • dongyou1926 2012-08-31 21:34
    关注

    You have to use the standard PHP function

    move_uploaded_file()
    

    to move an uploaded file to its place.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加