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.
Apologies, I missed off one part of the code. Thanks
//initialize new images to be uploaded
$files = array();
foreach ($_FILES['image'] as $k => $l) {
foreach ($l as $i => $v) {
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
}
}
// create an array here to hold file names
$uploaded = array();
foreach ($files as $file) {
$handle = new Upload($file);
if ($handle->uploaded) {
// create a little array for this set of pictures
$this_upload = array();
$handle->file_safe_name = true;
$handle->file_auto_rename = true;
$handle->file_max_size = '512000';
$handle->allowed = array('image/jpeg', 'image/jpg');
$handle->Process($dir_dest);
if ($handle->processed) {
echo $handle->file_dst_name;
// store the image filename
$this_upload['image'] = $handle->file_dst_name;
} else {
echo 'error : ' . $handle->error;
}
// add this set of pictures to the main array
$uploaded[] = $this_upload;
}
}