[英]AWS Elastic Beanstalk file upload not working
我们使用AWS Elastic Beanstalk来托管PHP应用程序,其中包括无法正常工作的文件上载工具。 我们有php.ini将tmp_upload_dir设置为/ tmp但它仍然不起作用。
我们刚刚从另一台服务器移动了网站,一切都在那里完美运行,但EB似乎不想让我们上传文件。
以下是我们使用的代码示例:
$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',
);
}
我遇到了同样的问题,发现我们需要两件事,两件都放在.htaccess文件中:
php_value upload_tmp_dir "/tmp"
php_value upload_max_filesize 10M
上载目录必须由Web服务器拥有,例如“webapp”或“daemon”,或者该帐户可写。 此外,max filesize必须适应您的上传。
就我而言,默认上传限制为2M,我的文件为4M。 这导致了一个空的$ _FILES数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.