dowbwrr3590709 2014-12-19 15:49
浏览 77
已采纳

AWS Elastic Beanstalk文件上传无效

We use AWS Elastic Beanstalk to host PHP applications which include file upload facilities which aren't working. We have php.ini set the tmp_upload_dir to /tmp but it still doesn't work.

We've just moved the site from another server, everything was working perfectly there, but EB doesn't seem to want to let us upload files.

Here's an example of the code we are using:

$imagePath = "/tmp/";

$allowedExts = array("gif", "jpeg", "jpg", "png", "GIF", "JPEG", "JPG", "PNG");
$temp = explode(".", $_FILES["img"]["name"]);
$extension = end($temp);

if ( in_array($extension, $allowedExts))
  {
  if ($_FILES["img"]["error"] > 0)
    {
         $response = array(
            "status" => 'error',
            "message" => 'ERROR Return Code: '. $_FILES["img"]["error"],
        );
        echo "Return Code: " . $_FILES["img"]["error"] . "<br>";
    }
  else
    {

      $filename = $_FILES["img"]["tmp_name"];
      list($width, $height) = getimagesize( $filename );

      move_uploaded_file($filename, $imagePath . $_FILES["img"]["name"]);

      $response = array(
        "status" => 'success',
        "url" => $imagePath.$_FILES["img"]["name"],
        "width" => $width,
        "height" => $height
      );

    }
  }
else
  {
   $response = array(
        "status" => 'error',
        "message" => 'something went wrong',
    );
  }
  • 写回答

1条回答 默认 最新

  • dongxiaoguang9108 2015-03-01 19:06
    关注

    I had the same problem, and found that we needed two things, both of which were put into the .htaccess file:

     php_value upload_tmp_dir "/tmp"
     php_value upload_max_filesize 10M
    

    The upload directory must be owned by the web server, e.g. "webapp", or "daemon", or writable by that account. In addition, the max filesize must accommodate your uploads.

    In my case, the upload limit was 2M by default, and my files were 4M. This resulted in an empty $_FILES array.

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog