473,722 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pls post mutiple image upload code & save filename in mysql

2 New Member
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.becaus e 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 4882
Markus
6,050 Recognized Expert Expert
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
4416
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 image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
4
4450
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 part, the scripts were created with http://phpcodegenie.sourceforge.net/
3
11762
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 table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
4
2455
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 a thumbnail.jpg .... all at the same time. Links to a working example would be appreciated. Thanks.
4
2326
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: File name: ViewAttachment File type: From localhost 1) "ViewAttachment" is the name of the aspx page and not the image file. 2) Its not picking up the file type of jpg. For ContentType I used
0
1668
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 applet. Shop script works with : <input type="file" name="id"/> but not with applet's: <input type="file" name="SourceFile_1"/> I just cannot figure out how to fix this :(
7
2365
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 camera or other, it uploads fine. However, If I want to rotate the image, or resize it with photoshop or simmilar, making sure to save it again as a jpg, the PHP upload won't upload the image.
3
4430
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 when iam using a normal web page... but can't in content page.... Code in Master Page <%@ Master Language="C#" AutoEventWireup="true" CodeFile="submaster.master.cs" Inherits="submaster" %> <%@ Register Assembly="AjaxControlToolkit"...
3
3103
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 move_upload_file, then i resize it using class "thumbnail.class.php" My next step was to embed company logo in it(which i already done) and save new embedded logo image to the path where i first upload the original image i mean i want to overwrite...
0
8739
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.