class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
The class itself handles one uploaded file at a time. In case of multiple uploads, the $_FILES array has a different structure, so you need first to re-structure it so it can be looped through, and each element of the array used to instanciate the class.
$files = array();
foreach ($_FILES['art_img'] as $k => $l) {
foreach ($l as $i => $v) {
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
}
}
and then:
foreach ($files as $file) {
$handle = new Upload($file);
if ($handle->uploaded) {
$handle->Process("./");
if ($handle->processed) {
echo 'OK';
// add your data in the database here
} else {
echo 'Error: ' . $handle->error;
}
} else {
echo 'Error: ' . $handle->error;
}
unset($handle);
}
and then: