473,394 Members | 1,802 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,394 software developers and data experts.

Uploading multiple images from a cms form to server & database

3
Good morning all,

I currently have a form that allows my client to upload one image and a load of other information, such as price, date, name etc.

He has asked if I can have it so that he can upload up to 4 images, and also all the rest of the information.

The images currently go to the server, and the paths with the other data goes into the database.

I have separate fields for each image in the table as I want to have control over how they get displayed.

Can somebody point me to a sensible tutorial, as I'm still learning or even better if they could post their code here so I can change for my use.

I'm still learning, so if you could include the php/mysql, the html and the form that would be awsome.
Mar 20 '12 #1
3 1827
Dormilich
8,658 Expert Mod 8TB
the main change you have to do is send/retrieve the data as a set (4 x image + info).
this is mainly done by adding square brackets to the form control name (ex. name="info[]" => $info_1 = $_POST['info'][0]). on the PHP side you would have then to loop over the set retrieved by the appropriate name.

for a visual distinguation in the HTML you can use the <fieldset> element.
Mar 20 '12 #2
accend
3
Hi Dormilich,

I know this sounds cheeky as but I think I know what your saying, but at this stage it would be great if you could add a bit more to code, so I can see the form, and the mysql/php.

There is another thread on here with a similar answer i think, but having trouble accessing it at the mo.

Cheers
Mar 20 '12 #3
accend
3
Hi again,

I got this code from the web and have tried to use it, with some degree of success.

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. set_time_limit(300);
  4.   $numoffile = 4;  // Set how many file uploads you want.
  5.  
  6.  
  7.   if ($_POST) {  
  8.     for ($i=0;$i<$numoffile;$i++) {  
  9.       if (trim($_FILES['myfiles']['name'][$i])!="") {  
  10.         $temp_file_location = $_FILES['myfiles']['tmp_name'][$i];
  11.         $old_upload_file = $_FILES['myfiles']['name'][$i];
  12. //        $newfile = $file_dir.$_FILES['myfiles']['name'][$i];
  13.         $newfile = $file_dir. $product_name . ".jpg";
  14.         $filemoved = move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], "./imgdata/stock/$old_upload_file");
  15.  
  16. // run any command here after every file upload.
  17. //$q24=mysql_query("update stock set stock_Image='x', stock_Image2='x', stock_Image3='x', stock_Image4='x' where stock_Id=$sr") or die (mysql_error()); 
  18.  
  19.         $j++;  
  20.       }  
  21.     }  
  22.   }  
  23.   if (isset($j)&&$j>0) print "Your file(s) has been uploaded.<br>";
  24.   //print $newfile;  
  25.   //print "<form method='post' enctype='multipart/form-data'>";  
  26.   for($i=0;$i<$numoffile;$i++) {  
  27.     print "<input type='file' name='myfiles[]' size='70'><br>";  
  28.   }  
  29.   //print "<input type='submit' name='action' value='Upload'>";  
  30.   //print "</form>";  
  31.  
  32. ?>
  33.  
The file goes to the server, but what I cant work out is how to get the path for each image into the database.

The bit that I put which I know is wrong to try and explain is below.

Expand|Select|Wrap|Line Numbers
  1. // run any command here after every file upload.
  2. //$q24=mysql_query("update stock set stock_Image='x', stock_Image2='x', stock_Image3='x', stock_Image4='x' where stock_Id=$sr") or die (mysql_error()); 
  3.  
And this is what Im currently using to handle the rest of the info in the form.

Expand|Select|Wrap|Line Numbers
  1. $name=$_POST['txtname'];
  2. $desc1=$_POST['e1m1'];        
  3. $meta=$_POST['txtmeta'];
  4. $sr=$_POST['srno1'];
  5. $name=$_POST['txtname'];
  6. $ref=$_POST['Ref'];
  7. $desc=$_POST['e1m1'];
  8. $maker=$_POST['Maker'];
  9. $date=$_POST['Date'];
  10. $weight=$_POST['Weight'];
  11. $height=$_POST['Height'];
  12. $depth=$_POST['Depth'];
  13. $width=$_POST['Width'];
  14. $price=$_POST['txtprice'];
  15. $sold=$_POST['txtsold'];
  16. $active=$_POST['active'];
  17. $pcats=$_POST['pcats'];
  18. $subcats=$_POST['subcats'];
  19.  
  20. $q24=mysql_query("update stock set stock_Name='$name', stock_MetaTitle='$meta', parent_Category='$pcats', sub_Category='$subcats', stock_Ref='$ref', stock_Description='$desc1', stock_Maker='$maker', stock_Date='$date', stock_Weight='$weight', stock_Height='$height', stock_Depth='$depth',stock_Width='$width', stock_Price='$price', stock_Sold='$sold', stock_Active='$active', stock_DateTime='$dt2' where stock_Id=$sr") or die (mysql_error());
  21. $flag=1;
  22. $conf="Data Updated Successfully - Click <a href='http://www.accendsandbox.co.uk/adminSallam/admin_categories.php'>here</a> to continue";
  23. $update="1";
  24. }
  25. else
  26. {
  27. $name=$_POST['txtname'];
  28. $ref=$_POST['Ref'];
  29. $desc=$_POST['e1m1'];
  30. $maker=$_POST['Maker'];
  31. $date=$_POST['Date'];
  32. $weight=$_POST['Weight'];
  33. $height=$_POST['Height'];
  34. $depth=$_POST['Depth'];
  35. $width=$_POST['Width'];
  36. $price=$_POST['txtprice'];
  37. $sold=$_POST['txtsold'];    
  38. $meta=$_POST['txtmeta'];
  39. $active=$_POST['active'];
  40. $pcats=$_POST['pcats'];
  41. $subcats=$_POST['subcats'];
  42.  
  43. $q=mysql_query("insert into stock (stock_Name, stock_MetaTitle, parent_Category, sub_Category, stock_Ref, stock_Description, stock_Maker, stock_Date, stock_Weight, stock_Height, stock_Depth, stock_Width, stock_Price, stock_Sold, stock_Active, stock_DateTime) values('$name','$meta','$pcats','$subcats','$ref','$desc','$maker','$date','$weight','$height','$depth','$width','$price','$sold','$active','$dt2')") or die (mysql_error());    
  44. $conf="Data Inserted Successfully - Click <a href='http://www.accendsandbox.co.uk/adminSallam/admin_stock.php'>here</a> to continue";
  45. $update=1;
  46. }
  47. }
  48.  
Mar 20 '12 #4

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

Similar topics

6
by: jmev7 | last post by:
Is there a script that will allow upload of multiple images at once to a FTP server, and simultaneously write that list to a MySQL table? I need to allow users to do something like this. Thanks.
3
by: Steve B. | last post by:
Request comments on the code that should be wriiten: 1. Need users to start a application from local network but only allow one instance of the application to run on EACH users machine while, at...
1
by: Ahmed Ayoub | last post by:
hello,,, can some one please tell me how to create tables (not on a database, but on a form) and input information into them .. and then retrieve the information from them ..
2
by: Just Me | last post by:
Hi, Im playing with this concept at the moment and was hoping to design an image retreival system which would allow me to place images into the web page " Where I want them", but draw them from...
14
w33nie
by: w33nie | last post by:
What I'm trying to do here, is upload a video to the ../video/ folder, and up to 5 images to the ../images/ folder. As well as the database information like title, content and each file's file...
7
by: Keith Hughitt | last post by:
Hi all, I am having trouble preloading images in a javascript application, and was wondering if anyone had any suggestions. Basically I have a bunch of images stored in a database as BLOBs. At...
1
by: =?Utf-8?B?UmFqYWdvcGFs?= | last post by:
Question How to Upload multiple images in asp.net? (ex.Like a gmail file field)
2
by: sarayu | last post by:
Hi All, How can i select multiple images by using shift or control key from my hard disk and upload it by using a submit button.For this what we use for selecting different images and...
7
by: nwclark | last post by:
Ok... I have a noobie issue. I am trying to upload a photo to specific directory on my server. (this is working correctly with the code below). However, I am also trying to rename the file and...
3
KeredDrahcir
by: KeredDrahcir | last post by:
I want to be able the upload multiple images at once. I can do a normal upload where the user browses for each image individually and I can also do where you have several browse images on the screen....
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
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...
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.