954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I want to upload multiple images to a sever using php/mysql

hi guys,
I am developing a website, and it needs people to upload images. I can write code for single upload but not multiple, please help.

Thanking you in advance!

alimoe
Junior Poster in Training
82 posts since Jun 2008
Reputation Points: 10
Solved Threads: 3
 

Use a file area like this

<input type="file" name="upload[]" >

then in you php script

foreach($_FILES['upload'] AS $file)
{
//HERE YOU DO YOUR FILE SAVING
//For the file array
}
Menster
Junior Poster
175 posts since Jun 2009
Reputation Points: 49
Solved Threads: 22
 

Looping is the way to go as Menster has just shown you here. in your html add as many file input fields as you want but name them all as upload[] so that PHP will take the name upload as an array when it is posted.
You can then loop through the array as you do your saving. I'm just explaining Menster's code

/*Happy coding*/

sureronald
Junior Poster
139 posts since May 2008
Reputation Points: 11
Solved Threads: 19
 

Here is an upload example I created a day or two ago. It needs to be modified a bit, but you get the basic idea.

Its pretty secure, making it so people can't upload scripts to the server and run them.

http://www.daniweb.com/forums/post905365-3.html

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

php code

if(isset($_POST['submit']))
	{
	   $video_title = $_POST['photo_title'];
	   $description = $_POST['description'];
	   
	
	   $MAX_SIZE = 2097152; 
	   
	   $filename = $_FILES['photo']['name'];
	   $filesize = $_FILES['photo']['size'];
	   if($filename!='')
	   {
	   
	   if( $filesize > $MAX_SIZE)
	   {
	        $err_msg = "<font color='red'>Your photo file size should not be exceed </font>";	 
			$filename =$_POST['hidden_file']; 
	   }
	   else
	   {
	   
			if(is_file("../photo/".$_POST['hidden_file']))
		   {
			  unlink("../photo/".$_POST['hidden_file']);
		   
		   }
	   
	   $filecontent = $_FILES['photo']['tmp_name'];
	   move_uploaded_file($filecontent,"../photo/".$filename);
	   }
	   
	   
	   }
	   else
	   {
	      	$filename =$_POST['hidden_file']; 
	   
	   }
	   
	  /*****VIDEO UPLOAD SECTION******/
	  
	   $sql = "UPDATE ".PHOTO." SET
	  								photo_title = '$photo_title',
									description = '$description',
									photo_file = '$filename',
									created_date = NOW()";
	  mysql_query($sql);
	   
	
	}
	
	$select = "SELECT * FROM ".photo;
	$read = mysql_query($select);
	$row=mysql_fetch_object($read);
	$title = $row->photo_title;
	$description = $row->description;
	$video_file = $row->photo_file;
	
	
?>

html code


     <table width="100%" height="500" border="0" cellspacing="0" cellpadding="0" >
				  
				  <tr>
					<td align="center" valign="top">
					  
					   <table width="100%" border="0" cellspacing="5" cellpadding="5">
                      <tr> 
                        <td width="30%"><h4>:: Photo Gallery</h4></td>
                        <td>&nbsp;</td>
                        <td width="70%"><?php echo $err_msg;?></td>
                      </tr>
                      <tr> 
                        <td align="right" class="smallfontbold">Photo Title</td>
                        <td>:</td>
                        <td><input type="text" name="photo_title" id="video_title" value="<?php echo $title;?>"></td>
                      </tr>
                      <tr> 
                        <td align="right" valign="top" class="smallfontbold">Photo 
                          Description</td>
                        <td>:</td>
                        <td valign="top"><textarea name="description" cols="4" rows="5" id="description" class="mceAdvanced"><?php echo $description;?></textarea></td>
                      </tr>
                      <tr> 
                        <td align="right" valign="top" class="smallfontbold">Photo 
                          Upload</td>
                        <td valign="top">:</td>
                        <td><input type="file" name="photo" id="photo" onKeyPress="return false;" >
						   <input type="hidden" name="hidden_file" value="<?php echo $photo_file;?>">
						</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>
						<div> </div>
						</td>
                      </tr>
                      <tr> 
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td><input type="submit" name="submit" value="SUBMIT"></td>
                      </tr>
                    </table>

					
					</td>
				  </tr>
				</table>
infserver
Newbie Poster
1 post since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

give me codes for uploading an image using php

prince pascal
Newbie Poster
1 post since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

How to upload multiple images ? through php,html and if neccessary javascript.
when i click on upload button it is not selecting more than one image

nagarjuna.king
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You