php – AWS Elastic Beanstalk文件上传无法正常工作
作者:互联网
我们使用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”或“守护程序”,或该帐户可写.此外,max filesize必须适应您的上传.
就我而言,默认上传限制为2M,我的文件为4M.这导致了一个空的$_FILES数组.
标签:php,file-upload,amazon-web-services,elastic-beanstalk 来源: https://codeday.me/bug/20190830/1766755.html