简体   繁体   English

AWS Elastic Beanstalk文件上传无效

[英]AWS Elastic Beanstalk file upload not working

We use AWS Elastic Beanstalk to host PHP applications which include file upload facilities which aren't working. 我们使用AWS Elastic Beanstalk来托管PHP应用程序,其中包括无法正常工作的文件上载工具。 We have php.ini set the tmp_upload_dir to /tmp but it still doesn't work. 我们有php.ini将tmp_upload_dir设置为/ tmp但它仍然不起作用。

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. 我们刚刚从另一台服务器移动了网站,一切都在那里完美运行,但EB似乎不想让我们上传文件。

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',
    );
  }

I had the same problem, and found that we needed two things, both of which were put into the .htaccess file: 我遇到了同样的问题,发现我们需要两件事,两件都放在.htaccess文件中:

 php_value upload_tmp_dir "/tmp"
 php_value upload_max_filesize 10M

The upload directory must be owned by the web server, eg "webapp", or "daemon", or writable by that account. 上载目录必须由Web服务器拥有,例如“webapp”或“daemon”,或者该帐户可写。 In addition, the max filesize must accommodate your uploads. 此外,max filesize必须适应您的上传。

In my case, the upload limit was 2M by default, and my files were 4M. 就我而言,默认上传限制为2M,我的文件为4M。 This resulted in an empty $_FILES array. 这导致了一个空的$ _FILES数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM