473,395 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

pls post mutiple image upload code & save filename in mysql

can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading.

i develop program,which can upload many file in folder.problem is,am unable to save my file name in to database.because i used same name for all input file type as file[]. i dont know get name of file.below i presented my coding for ur view.fed up with my coding..pls guide with new coding r suggest in my coding

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // make a note of the current working directory relative to root.
  4. $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
  5.  
  6. // make a note of the location of the upload handler
  7. $uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'multiple.upload.php';
  8.  
  9. // set a max file size for the html upload form
  10. $max_file_size = 30000000000; // size in bytes
  11.  
  12. // now echo the html page
  13. ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  14. "http://www.w3.org/TR/html4/strict.dtd">
  15.  
  16. <html lang="en">
  17. <head>
  18. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  19.  
  20. <link rel="stylesheet" type="text/css" href="stylesheet.css">
  21.  
  22. <title>Upload form</title>
  23.  
  24. </head>
  25.  
  26. <body>
  27.  
  28. <form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">
  29.  
  30. <h1>
  31. Upload form
  32. </h1>
  33.  
  34. <p>
  35. <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
  36. </p>
  37.  
  38. <p>
  39. <label for="file1">File to upload:</label>
  40. <input id="file1" type="file" name="file[]">
  41. </p>
  42.  
  43. <p>
  44. <label for="file2">File to upload:</label>
  45. <input id="file2" type="file" name="file[]">
  46. </p>
  47.  
  48. <p>
  49. <label for="file3">File to upload:</label>
  50. <input id="file3" type="file" name="file[]">
  51. </p>
  52.  
  53. <p>
  54. <label for="submit">Press to...</label>
  55. <input id="submit" type="submit" name="submit" value="Upload us!">
  56. </p>
  57.  
  58. </form>
  59.  
  60.  
  61. </body>
  62.  
  63. </html>
  64.  
  65. <?php 
  66.  
  67. // make a note of the current working directory, relative to root.
  68. $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
  69.  
  70. // make a note of the directory that will recieve the uploaded files
  71. $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';
  72.  
  73. // make a note of the location of the upload form in case we need it
  74. $uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'multiple.upload.php';
  75.  
  76. // make a note of the location of the success page
  77. $uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';
  78.  
  79. // name of the fieldname used for the file in the HTML form
  80. $fieldname = 'file';
  81.  
  82. //echo'<pre>';print_r($_FILES);exit;
  83.  
  84.  
  85.  
  86. // Now let's deal with the uploaded files
  87.  
  88. // possible PHP upload errors
  89. $errors = array(1 => 'php.ini max file size exceeded', 
  90. 2 => 'html form max file size exceeded', 
  91. 3 => 'file upload was only partial', 
  92. 4 => 'no file was attached');
  93.  
  94. // check the upload form was actually submitted else print form
  95. if(isset($_POST['submit']))
  96. {
  97. // or error('the upload form is neaded', $uploadForm);
  98.  
  99. // check if any files were uploaded and if 
  100. // so store the active $_FILES array keys
  101. $active_keys = array();
  102. foreach($_FILES[$fieldname]['name'] as $key => $filename)
  103. {
  104. if(!empty($filename))
  105. {
  106. $active_keys[] = $key;
  107. }
  108. }
  109.  
  110. // check at least one file was uploaded
  111. count($active_keys)
  112. or error('No files were uploaded', $uploadForm);
  113.  
  114. // check for standard uploading errors
  115. foreach($active_keys as $key)
  116. {
  117. ($_FILES[$fieldname]['error'][$key] == 0)
  118. or error($_FILES[$fieldname]['tmp_name'][$key].': '.$errors[$_FILES[$fieldname]['error'][$key]], $uploadForm);
  119. }
  120.  
  121. // check that the file we are working on really was an HTTP upload
  122. foreach($active_keys as $key)
  123. {
  124. @is_uploaded_file($_FILES[$fieldname]['tmp_name'][$key])
  125. or error($_FILES[$fieldname]['tmp_name'][$key].' not an HTTP upload', $uploadForm);
  126. }
  127.  
  128. // validation... since this is an image upload script we 
  129. // should run a check to make sure the upload is an image
  130. foreach($active_keys as $key)
  131. {
  132. @getimagesize($_FILES[$fieldname]['tmp_name'][$key])
  133. or error($_FILES[$fieldname]['tmp_name'][$key].' not an image', $uploadForm);
  134. }
  135.  
  136. // make a unique filename for the uploaded file and check it is 
  137. // not taken... if it is keep trying until we find a vacant one
  138. foreach($active_keys as $key)
  139. {
  140. $now = time();
  141. while(file_exists($uploadFilename[$key] = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'][$key]))
  142. {
  143. $now++;
  144. }
  145. }
  146.  
  147. // now let's move the file to its final and allocate it with the new filename
  148. foreach($active_keys as $key)
  149. {
  150. @move_uploaded_file($_FILES[$fieldname]['tmp_name'][$key], $uploadFilename[$key])
  151. or error('receiving directory insuffiecient permission', $uploadForm);
  152. }
  153.  
  154. // If you got this far, everything has worked and the file has been successfully saved.
  155. // We are now going to redirect the client to the success page.
  156. header('Location: ' . $uploadSuccess);
  157.  
  158. // make an error handler which will be used if the upload fails
  159. function error($error, $location, $seconds = 5)
  160. {
  161. header("Refresh: $seconds; URL=\"$location\"");
  162. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
  163. '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
  164. '<html lang="en">'."\n".
  165. ' <head>'."\n".
  166. ' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
  167. ' <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
  168. ' <title>Upload error</title>'."\n\n".
  169. ' </head>'."\n\n".
  170. ' <body>'."\n\n".
  171. ' <div id="Upload">'."\n\n".
  172. ' <h1>Upload failure</h1>'."\n\n".
  173. ' <p>An error has occured: '."\n\n".
  174. ' <span class="red">' . $error . '...</span>'."\n\n".
  175. ' The upload form is reloading</p>'."\n\n".
  176. ' </div>'."\n\n".
  177. '</html>';
  178. exit;
  179. } // end error handler
  180. }
Sep 21 '09 #1
1 4842
Markus
6,050 Expert 4TB
chennaibala,

Please understand that Bytes.com is a website dedicated to helping people solve their tech/IT related issues. It is not a site where you can request code and have it sent to you - that is against our forum guidelines[1].

Furthermore, when you post code, please use [code] your code goes here... [/code]. Again, this is a forum guideline[1].

If you would like to refine your question to target specific problems, and also show us that you are willing to do the work yourself, then post the question again as a reply to this thread.

Thanks,
Mark.

[1] Forum Guidelines
Sep 21 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
4
by: DH | last post by:
I have a "file upload form" that works OK, but I have been unsuccessful in my attempt to also resize the uploaded .JPG (if it is too wide), over-writing the original .JPG, and then create and save...
4
by: moondaddy | last post by:
Using vb.net I need to download image files to the client browser where they can save to disk. Below is some sample code I'm using. when I run this the File Download window in the browser says: ...
0
by: Event Horizon | last post by:
Hi, I'm trying to add an simple upload applet to shopping cart script. My new applet form sends all needed post fields ( quantity, product, etc... ) but the "file" post field is hardcoded in...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
3
by: neovantage | last post by:
Hey all, i have created image by mixing logo and the original image. It create image and show in the same window. I have done 3 steps for this. First i upload an image to my server by using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.