Save this file as
index.php, upload it n test......
PHP Code:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
</head>
<body>
<form enctype="multipart/form-data" action="" method="POST">
<input name='image_upload[]' type='file' multiple=20 /><br>
<input name='image_upload[]' type='file' multiple=20 /><br>
<input name='image_upload[]' type='file' multiple=20 /><br>
<input type="submit" value="Send File" />
</form>
<?php
$tFiles = $_FILES['image_upload']['tmp_name'];
print_r($_FILES);
for($i = 0; $i < count($tFiles); ++$i)
{
performaLocalUpload($_FILES['image_upload']['tmp_name'][$i], $uploadDir, $allowed, $maxfileSize);
}
function performaLocalUpload($files, $uploadDir, $allowed, $maxfileSize)
{
$uploadDir = $_SERVER['DOCUMENT_ROOT'] .'uploads';
if($ext = checkitsaValidImage($files))
{
$new_name = gen_uniqueFilename() . $ext; // we will give an unique name.
$uploadFilePath = $uploadDir .'/'. $new_name;
if (!move_uploaded_file($files, $uploadFilePath)) {
trigger_error('Failed to upload image');
}
}
}
function checkitsaValidImage($files)
{
include $_SERVER['DOCUMENT_ROOT'] .'/config.php';
$imageInfo = getimagesize($files);
$size = filesize($files);
$sResult = '';
if(!$imageInfo) {
trigger_error('Error not an image.');
}
if(!empty($imageInfo) && !in_array($imageInfo['mime'], $allowed)) {
trigger_error('Error invalid file.');
}
else if($imageInfo[0] > $maxWidth || $imageInfo[1] > $maxHeight) {
trigger_error('Error image size too big.');
}
else if($size > $maxfileSize) {
trigger_error('Error file size too big.');
}
else
{
$sResult = image_type_to_extension($imageInfo[2], true);
}
return $sResult;
}
?>
</body>
</html>
This script works 100%, you need to make 3 vars for checkitsanImage() function, go figure..
Credits: me (Chris-2k)