Monday, 7 May 2012

Upload Multiple Files in PHP

<form action="" method="post" enctype="multipart/form-data">
File: <input type="file" name="file[]"/><br/>
File: <input type="file" name="file[]"/><br/>
File: <input type="file" name="file[]"/><br/>
<input type="submit" name="submit" value="Upload"/>
</form>

<?php
if(isset($_POST['submit'])){
$destpath = "photos/" ;



while(list($key,$value) = each($_FILES["file"]["name"])) {
   
if(!empty($value))
{
if (($_FILES["file"]["type"][$key] == "image/gif")
|| ($_FILES["file"]["type"][$key] == "image/jpeg")
|| ($_FILES["file"]["type"][$key] == "text/plain")
|| ($_FILES["file"]["type"][$key] == "application/pdf")
|| ($_FILES["file"]["type"][$key] == "image/pjpeg")
&& ($_FILES["file"]["size"][$key] < 2000000))
{



$source = $_FILES["file"]["tmp_name"][$key] ;
$filename = $_FILES["file"]["name"][$key] ;
move_uploaded_file($source, $destpath . $filename) ;
echo "Uploaded: " . $destpath . $filename . "<br/>" ;
}
else{echo "error in upload";}
}
}
}
?>

No comments:

Post a Comment