this the html markup for multiple upload..i want to perform validation to it..
1)check if the file is 5 mb
2)check if it is jpg,gif only image file
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="file[]" multiple="multiple">
<input type="submit" value="upload">
</form>
here is the php code
if(!empty($_FILES['file'])){
foreach($_FILES['file']['name'] as $key => $name)
{
if($_FILES['file']['error'][$key] == 0 && move_uploaded_file($_FILES['file']['tmp_name'][$key], "images/{$name}")){
$uploaded[] = $name;
}
}
print_r($uploaded);
}
right now its just uploading the file without any validation…i cant figure out wat to do to check the size and check if its image type only…..please php experts help me out
when i try to use this it directyl uploads
if($_FILES['file']['size'][$key] > 5000){
echo 'file must be under 5 mb';
}else{
move_uploaded_file($_FILES['file']['tmp_name'][$key], "images/{$name}")
}
1 Answer