Jump to content

[SOLVED] Multi uploading files question


graham23s

Recommended Posts

Hi Guys,

 

i have a screen with a drop down selection box, 1-5, the user can select how many files they want to upload, depending on what they select THAT number of input boxes are displayed for them to upload, besides each i have a hidden field which stores the number of uploads they chose:

 

like:

 

<?php  
                ## how many nfos ########################################################
                for($n=0; $n < $needednfos; $n++) { 
                            
                echo '<input type="hidden" name="need_nfo" value="'.$needednfos.'"><input type="file" name="nfo[]"><br />';
                
                }                
?>
                </td>
                </tr>
                <tr>
                <td align="right" /><b>RAR/ZIP</b></td><td align="left">
<?php

                for($i=0; $i < $uploadsneeded; $i++){

                echo '<input type="hidden" name="need_nzb" value="'.$uploadsneeded.'"><input type="file" name="nzb[]" ><br />';

                } 
?>

 

the part im not sure about is how to go about inserting all the uploaded files into mysql and moving them all, surely i dont need to write the whole upload code for every fields , i take it some kind of loop is needed just not sure how to start it

 

any input would be appreciated

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/67298-solved-multi-uploading-files-question/
Share on other sites

OK heres a basic example

 

 

<form method="post" enctype="multipart/form-data" >
<input name="images[]" type="file" /><br />
<input name="images[]" type="file" /><br />
<input name="images[]" type="file" /><br />
<input name="submit" type="submit" value="sumit" />
</form>
<?php
upload();
function upload()
{
if( isset($_FILES) )
{
	foreach($_FILES['images']['name'] as $K => $V)
	{
		if(!empty($V))
		{
			$target_path = "uploads/";
			$target_path = $target_path . basename($V); 
			if(@move_uploaded_file($_FILES['images']['tmp_name'][$K], $target_path))
			{
				echo "The file ".basename($V)." has been uploaded<br />";
			} else{
				echo "There was an error uploading the file '".basename($V)."', please try again!<br />";
			}
		}
	}
}
}


?>

 

NOTE: remove the @ from "@move_uploaded_file" if you have problems (it will show the error)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.