943,929 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 4554
  • PHP RSS
Jul 2nd, 2009
0

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

Expand Post »
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!
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
alimoe is offline Offline
82 posts
since Jun 2008
Jul 3rd, 2009
0

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

Use a file area like this
PHP Syntax (Toggle Plain Text)
  1. <input type="file" name="upload[]" >
then in you php script
PHP Syntax (Toggle Plain Text)
  1. foreach($_FILES['upload'] AS $file)
  2. {
  3. //HERE YOU DO YOUR FILE SAVING
  4. //For the file array
  5. }
Reputation Points: 49
Solved Threads: 22
Junior Poster
Menster is offline Offline
175 posts
since Jun 2009
Jul 3rd, 2009
0

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

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*/
Reputation Points: 11
Solved Threads: 18
Junior Poster
sureronald is offline Offline
139 posts
since May 2008
Jul 3rd, 2009
0

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

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Jul 7th, 2009
0

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

php code

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
infserver is offline Offline
1 posts
since Jul 2009
Jul 7th, 2009
0

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

give me codes for uploading an image using php
Reputation Points: 10
Solved Threads: 0
Newbie Poster
prince pascal is offline Offline
1 posts
since Jul 2009
Aug 5th, 2011
0

uploading multiple images

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nagarjuna.king is offline Offline
1 posts
since Aug 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Zend reference websites and interview questions
Next Thread in PHP Forum Timeline: how to get values from text using php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC