I want to upload multiple files and store them in a folder and get the path and store it in the database... Any good example you looked for doing multiple file upload...
I know this is an old post but some further explanation might be useful for someone trying to upload multiple files... Here is what you need to do:
name="inputName[]"
multiple="multiple"
or just multiple
"$_FILES['inputName']['param'][index]"
array_filter()
before count.Here is a down and dirty example (showing just relevant code)
HTML:
<input name="upload[]" type="file" multiple="multiple" />
PHP:
//$files = array_filter($_FILES['upload']['name']); //something like that to be used before processing files.
// Count # of uploaded files in array
$total = count($_FILES['upload']['name']);
// Loop through each file
for( $i=0 ; $i < $total ; $i++ ) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a file path
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
//Handle other code here
}
}
}
Hope this helps out!
Nice link on:
PHP Single File Uploading with vary basic explanation.
PHP file uploading with the Validation
PHP Multiple Files Upload With Validation Click here to download source code
PHP/jQuery Multiple Files Upload With The ProgressBar And Validation (Click here to download source code)
How To Upload Files In PHP And Store In MySql Database (Click here to download source code)
extract($_POST);
$error=array();
$extension=array("jpeg","jpg","png","gif");
foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name)
{
$file_name=$_FILES["files"]["name"][$key];
$file_tmp=$_FILES["files"]["tmp_name"][$key];
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
if(in_array($ext,$extension))
{
if(!file_exists("photo_gallery/".$txtGalleryName."/".$file_name))
{
move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$file_name);
}
else
{
$filename=basename($file_name,$ext);
$newFileName=$filename.time().".".$ext;
move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$newFileName);
}
}
else
{
array_push($error,"$file_name, ");
}
}
and you must check your HTML code
<form action="create_photo_gallery.php" method="post" enctype="multipart/form-data">
<table width="100%">
<tr>
<td>Select Photo (one or multiple):</td>
<td><input type="file" name="files[]" multiple/></td>
</tr>
<tr>
<td colspan="2" align="center">Note: Supported image format: .jpeg, .jpg, .png, .gif</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Create Gallery" id="selectedButton"/></td>
</tr>
</table>
</form>
Nice link on:
PHP Single File Uploading with vary basic explanation.
PHP file uploading with the Validation
PHP Multiple Files Upload With Validation Click here to download source code
PHP/jQuery Multiple Files Upload With The ProgressBar And Validation (Click here to download source code)
How To Upload Files In PHP And Store In MySql Database (Click here to download source code)