Jump to content

Multi Upload


raven2009

Recommended Posts

the best you can do i have x amount of file input boxes and select an file for each. name them all something like 'file[]' ensuring you have the '[]' in the name. this will submit the x amount of files as an array. simply loop through them on the processing page.

 

$x = $_FILES['file']; // this is an array containing all of the files selected
for($i = 0; $i < count($x); $i++){
echo $x[$i]['name'];
}

Link to comment
https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803510
Share on other sites

the best you can do i have x amount of file input boxes and select an file for each. name them all something like 'file[]' ensuring you have the '[]' in the name. this will submit the x amount of files as an array. simply loop through them on the processing page.

 

$x = $_FILES['file']; // this is an array containing all of the files selected
for($i = 0; $i < count($x); $i++){
echo $x[$i]['name'];
}

 

ok thanks for you reply how would i implement that in this code in the tables part or the 1st part?

 

table?

<table width="409" border="1" align="center" bordercolor="#C9D4E3" bgcolor="#C9D4E3">

						       <form action="" enctype="multipart/form-data" method="post"> 
                                       <tr> 
                                        <td width="189" bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailer Image </strong></div></td> 
                                        <td width="344" bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> 
                                            <label> 
                                            <input name="uploadedfile" type="file" /> 
                                            </label> 
                                          </div></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailer Name </strong></div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <label> 
                                            <input name="retailername" type="text" id="retailername"> 
                                            </label> 
                                          </div></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailer Category </strong></div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                        <select name="category">
									<?php
									$listCategories="select * from categories";
									$listCats=mysql_query($listCategories);
									while($row=mysql_fetch_array($listCats))
									{
									?>
									<option value="<?php echo $row['id']; ?>"><?php echo $row['category']; ?></option>
									<?
									}
									?></select>
                                          </div></td> 
                                      </tr> 									  
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailer Keywords</strong></div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <label> 
                                            <input name="keywords" type="text" id="keywords"> 
                                            </label> 
                                          </div></td> 
                                      </tr> 
                               
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center" class="style1"> 
                                            <p><strong>Cashback Offered</strong></p> 
                                            </div> 
                                          <label></label></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <p> 
                                              <label> 
                                              <input type="radio" name="cashback" value="£"> 
£</label> 
                                              <br> 
                                              <label> 
                                              <input type="radio" name="cashback" value="%"> 
                                              %</label> 
                                              <br> 
                                              <label></label> 
                                            </p> 
                                          </div></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <p> </p> 
                                            <p><strong>Cash Back Amount </strong></p> 
                                          </div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <p> </p> 
                                            <p> 
                                              <label> 
                                              <input name="cashback_amount" type="text" id="cashback_amount"> 
                                              </label> 
                                            </p> 
                                          </div></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <p><strong>Retailer Short Info</strong><strong> </strong></p> 
                                            </div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <label> 
                                            <textarea name="shortinfo" id="shortinfo"></textarea> 
                                            </label> 
                                          </div></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <p><strong>Terms of sale</strong></p> 
                                            </div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <label> 
                                            <textarea name="terms" id="terms"></textarea> 
                                            </label> 
                                          </div></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailers Full Info </strong></div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <label> 
                                            <textarea name="fullinfo" id="fullinfo"></textarea> 
                                            </label> 
                                          </div></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <p><strong>Retailers Link</strong></p> 
                                            </div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <label> 
                                            <textarea name="link" id="link"></textarea> 
                                            </label> 
                                          </div></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"></div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"></div></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Other Info </strong></div></td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><label> 
                                          <div align="center"> 
                                            <textarea name="other" id="other"></textarea> 
                                          </div> 
                                          </label></td> 
                                      </tr> 
                                      <tr> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"> </td> 
                                        <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> 
                                            <p> </p> 
                                            <p> 
                                              <input name="addRetailer" value="addRetailer" type="hidden"> 
                                              <input name="image" type="image" src="../images/site/submit_button_green.gif" alt="Submit" width="124" height="24" border="0"> 
                                            </p> 
                                          </div></td> 
                                      </tr> 
                                    </table>

 

(function)


<?php

require_once('../config.php');

if(isset($_POST['addRetailer']) && $_POST['addRetailer']=='addRetailer')
{

$target_path = "uploads/";
$img_path=time()."_".basename( $_FILES['uploadedfile']['name']);
$target_path = $target_path .$img_path ; 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
   // echo "The file ".  basename( $_FILES['uploadedfile']['name']).     " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

$retailername=$_POST['retailername'];
$keywords=$_POST['keywords'];
$cashback=$_POST['cashback'];
$cashback_amount=$_POST['cashback_amount'];
$shortinfo=$_POST['shortinfo'];
$terms=$_POST['terms'];
$fullinfo=$_POST['fullinfo'];
$link=$_POST['link'];
$other=$_POST['other'];
$category=$_POST['category'];



$addRetailer="insert into retailers(id,retailername,keywords,cashback,cashback_amount,shortinfo,terms,fullinfo,link,other,image,category) 
values('','$retailername','$keywords','$cashback','$cashback_amount','$shortinfo','$terms','$fullinfo','$link','$other','$img_path','$category')";
//echo $register;
$addRetailer=mysql_query($addRetailer);

if($addRetailer)
{
?> 
<script language="javascript1.1">
alert('Store added successfully!');
</script> 
<?
}
else
{
?> 
<script language="javascript1.1">
alert('Store not added! please try again.');
</script> 
<?
}


}

?>

Link to comment
https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803544
Share on other sites

the best you can do i have x amount of file input boxes and select an file for each. name them all something like 'file[]' ensuring you have the '[]' in the name. this will submit the x amount of files as an array. simply loop through them on the processing page.

 

$x = $_FILES['file']; // this is an array containing all of the files selected
for($i = 0; $i < count($x); $i++){
echo $x[$i]['name'];
}

 

???

Link to comment
https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803675
Share on other sites

Ahem.... You can do multiple file uploads like this:

 

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

 

Then the PHP can get complicated, because there's lots of checks you'll want to do for file uploads.

 

I do the following just to get a more easy-to-work with array from $_FILES

		$files = array();
		foreach ($_FILES[$key]['tmp_name'] as $n => $dummy)
			if (!empty($_FILES[$key]['tmp_name'][$n]))
				$files[$n] = array(
					'tmp_name' => $_FILES[$key]['tmp_name'][$n],
					'name' => $_FILES[$key]['name'][$n],
					'size' => $_FILES[$key]['size'][$n],
					'error' => $_FILES[$key]['error'][$n],
					'type' => $_FILES[$key]['type'][$n],
				);

 

$key would be 'upload_files' in this example, because the name of the upload field is 'upload_files'

 

I then do foreach ($files as $file) to process each file individually making checks like file size, file extension, etc etc

Link to comment
https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803702
Share on other sites

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.