AWS Elastic Beanstalk file upload not working
We are using AWS Elastic Beanstalk to host PHP applications that include file uploads that don't work. We have php.ini set tmp_upload_dir to / tmp, but it still doesn't work.
We just moved the site from another server, everything worked fine there, but EB doesn't seem to want to upload files.
Here's some sample code we're 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',
);
}
+3
flyersun
source
to share
1 answer
I had the same problem and it turned out 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 download directory must be owned by the web server eg. "webapp", or "daemon", or writable by this account. Also, the maximum file size should match your downloads.
In my case, the default upload limit was 2M and my files were 4M. The result was an empty $ _FILES array.
+5
JDA3
source
to share