Using this code to upload files from a form. However it only uploads the last image, missing out any before hand.
$uploadpath = get_img_path($username).$id."/";
@mkdir($uploadpath);
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
if( exif_imagetype($tmp_name) != IMAGETYPE_JPEG)
$errormsg=$errormsg."Unable to upload Picture ".($key+1)." at the moment. It is not a valid jpg image. Please edit the car to add the picture.<br>";
else
{
$name = $uploadpath.$key.".jpg";
//check file doesnt already exist
if (is_file($name))
@unlink($name);
$name = $uploadpath.($key+1).".jpg";
echo "tmp: $tmp_name name: $name <br>";
if (!move_uploaded_file($tmp_name, $name))
$errormsg=$errormsg."unable to upload file";
}
}
}
the echo line before move_uploaded_file is for debugin and reports the temp name, and upload name correctely so I cant figure out why it wont upload the first files.