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

Reply

Join Date: Jun 2008
Posts: 52
Reputation: alimoe is an unknown quantity at this point 
Solved Threads: 2
alimoe's Avatar
alimoe alimoe is offline Offline
Junior Poster in Training

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

 
0
  #1
Jul 2nd, 2009
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!
I am a Novice..............
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 172
Reputation: Menster is an unknown quantity at this point 
Solved Threads: 22
Menster's Avatar
Menster Menster is offline Offline
Junior Poster

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

 
0
  #2
Jul 3rd, 2009
Use a file area like this
  1. <input type="file" name="upload[]" >
then in you php script
  1. foreach($_FILES['upload'] AS $file)
  2. {
  3. //HERE YOU DO YOUR FILE SAVING
  4. //For the file array
  5. }
$me = new Person();
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 97
Reputation: sureronald is an unknown quantity at this point 
Solved Threads: 16
sureronald sureronald is offline Offline
Junior Poster in Training

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

 
0
  #3
Jul 3rd, 2009
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*/
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

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

 
0
  #4
Jul 3rd, 2009
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
Last edited by kkeith29; Jul 3rd, 2009 at 3:28 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 1
Reputation: infserver is an unknown quantity at this point 
Solved Threads: 0
infserver infserver is offline Offline
Newbie Poster

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

 
0
  #5
Jul 7th, 2009
php code

  1. if(isset($_POST['submit']))
  2. {
  3. $video_title = $_POST['photo_title'];
  4. $description = $_POST['description'];
  5.  
  6.  
  7. $MAX_SIZE = 2097152;
  8.  
  9. $filename = $_FILES['photo']['name'];
  10. $filesize = $_FILES['photo']['size'];
  11. if($filename!='')
  12. {
  13.  
  14. if( $filesize > $MAX_SIZE)
  15. {
  16. $err_msg = "<font color='red'>Your photo file size should not be exceed </font>";
  17. $filename =$_POST['hidden_file'];
  18. }
  19. else
  20. {
  21.  
  22. if(is_file("../photo/".$_POST['hidden_file']))
  23. {
  24. unlink("../photo/".$_POST['hidden_file']);
  25.  
  26. }
  27.  
  28. $filecontent = $_FILES['photo']['tmp_name'];
  29. move_uploaded_file($filecontent,"../photo/".$filename);
  30. }
  31.  
  32.  
  33. }
  34. else
  35. {
  36. $filename =$_POST['hidden_file'];
  37.  
  38. }
  39.  
  40. /*****VIDEO UPLOAD SECTION******/
  41.  
  42. $sql = "UPDATE ".PHOTO." SET
  43. photo_title = '$photo_title',
  44. description = '$description',
  45. photo_file = '$filename',
  46. created_date = NOW()";
  47. mysql_query($sql);
  48.  
  49.  
  50. }
  51.  
  52. $select = "SELECT * FROM ".photo;
  53. $read = mysql_query($select);
  54. $row=mysql_fetch_object($read);
  55. $title = $row->photo_title;
  56. $description = $row->description;
  57. $video_file = $row->photo_file;
  58.  
  59.  
  60. ?>
  61.  
  62. html code
  63.  
  64.  
  65. <table width="100%" height="500" border="0" cellspacing="0" cellpadding="0" >
  66.  
  67. <tr>
  68. <td align="center" valign="top">
  69.  
  70. <table width="100%" border="0" cellspacing="5" cellpadding="5">
  71. <tr>
  72. <td width="30%"><h4>:: Photo Gallery</h4></td>
  73. <td>&nbsp;</td>
  74. <td width="70%"><?php echo $err_msg;?></td>
  75. </tr>
  76. <tr>
  77. <td align="right" class="smallfontbold">Photo Title</td>
  78. <td>:</td>
  79. <td><input type="text" name="photo_title" id="video_title" value="<?php echo $title;?>"></td>
  80. </tr>
  81. <tr>
  82. <td align="right" valign="top" class="smallfontbold">Photo
  83. Description</td>
  84. <td>:</td>
  85. <td valign="top"><textarea name="description" cols="4" rows="5" id="description" class="mceAdvanced"><?php echo $description;?></textarea></td>
  86. </tr>
  87. <tr>
  88. <td align="right" valign="top" class="smallfontbold">Photo
  89. Upload</td>
  90. <td valign="top">:</td>
  91. <td><input type="file" name="photo" id="photo" onKeyPress="return false;" >
  92. <input type="hidden" name="hidden_file" value="<?php echo $photo_file;?>">
  93. </td>
  94. </tr>
  95. <tr>
  96. <td>&nbsp;</td>
  97. <td>&nbsp;</td>
  98. <td>
  99. <div> </div>
  100. </td>
  101. </tr>
  102. <tr>
  103. <td>&nbsp;</td>
  104. <td>&nbsp;</td>
  105. <td><input type="submit" name="submit" value="SUBMIT"></td>
  106. </tr>
  107. </table>
  108.  
  109.  
  110. </td>
  111. </tr>
  112. </table>
Last edited by peter_budo; Jul 8th, 2009 at 7:49 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 1
Reputation: prince pascal is an unknown quantity at this point 
Solved Threads: 0
prince pascal prince pascal is offline Offline
Newbie Poster

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

 
0
  #6
Jul 7th, 2009
give me codes for uploading an image using php
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 724 | Replies: 5
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC