Jump to content

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.