I am trying to write a PHP script that can upload multiple files.
for($i=0;$i<count($_FILES['uploadimg']['name']);$i++){
$name = $_FILES['uploadimg']['name'][$i];
$type = $_FILES['uploadimg']['type'][$i];
$filepath = $_FILES['uploadimg']['tmp_name'][$i];
$size = getimagesize($filepath);
$img = file_get_contents($filepath);
//insert into database
}
The problem is that the variables are not being populated the way they should.
When I upload a jpeg "image.jpg", I have discovered that the variables have the following values: (by replacing database code with echo
s and var_export
s)
$name = 'image.jpg'; // good
$type = ''; // not good
$filepath = ''; // not good
$size = false; // not good
$img = false; // not good
I should note that I realize $size
and $img
are dependent on $filepath
being a valid file path.
Could anyone offer some insight into what is going wrong or what I am missing? I've been playing around with the code for a day now, and cannot come up with a solution.
Update:
print_r($_FILES)
on 3 images returns:
Array (
[uploadimg] => Array (
[name] => Array (
[0] => test1.jpg
[1] => test2.jpg
[2] => test3.jpg
)
[type] => Array (
[0] => image/jpeg
[1] =>
[2] => image/jpeg
)
[tmp_name] => Array (
[0] => /tmp/phpkC6f2F
[1] =>
[2] => /tmp/phpgFrPl8
)
[error] => Array (
[0] => 0
[1] => 1
[2] => 0
)
[size] => Array (
[0] => 238906
[1] => 0
[2] => 237308
)
)
)
Can I then assume this means the image is too big?