SlayerACC
07-01-2010, 07:36 PM
How can you take the data from an array and seperate the information and post it to your database.??
Thanks, S.
Thanks, S.
|
||||
Array HelpSlayerACC 07-01-2010, 07:36 PM How can you take the data from an array and seperate the information and post it to your database.?? Thanks, S. Keleth 07-01-2010, 07:43 PM What do you mean? Example? SlayerACC 07-01-2010, 07:51 PM I am working on creating a multi upload script and would like to put the image name into the database along with other information from the form. it all works great .. the images upload.. I just want to add the image names to the database..?? Form: <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Multiple image upload script</title> <meta name="GENERATOR" content="Arachnophilia 4.0"> <meta name="FORMATTER" content="Arachnophilia 4.0"> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <? $max_no_img=4; // Maximum number of images value to be set here echo "<form method=post action=addimgck.php enctype='multipart/form-data'>"; echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>"; for($i=1; $i<=$max_no_img; $i++){ echo "<tr><td>Images $i</td><td> <input type=file name='images[]' class='bginput'></td></tr>"; } echo "<tr><td colspan=2 align=center><input type=submit value='Add Image'></td></tr>"; echo "</form> </table>"; ?> </body> </html> Upload script <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Multiple image upload script</title> <meta name="GENERATOR" content=""> <meta name="FORMATTER" content=""> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <? while(list($key,$value) = each($_FILES['images']['name'])) { if(!empty($value)) { $filename = $value; $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line $add = "upimg/$filename"; // echo $_FILES['images']['type'][$key]; // echo "<br>"; echo "$filename"; copy($_FILES['images']['tmp_name'][$key], $add); chmod("$add",0777); } } ?> </body> </html> Thanks, S. Keleth 07-01-2010, 08:26 PM The images filename you mean? $filename above? And I assume a normalized database structure? Simply enough (how I would do it anyway) $insertQuery = "INSERT INTO images (imgName) VALUES "; while(list($key,$value) = each($_FILES['images']['name'])) { if(!empty($value)) { $filename = $value; $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line $add = "upimg/$filename"; // echo $_FILES['images']['type'][$key]; // echo "<br>"; $insertQuery .= "('$filename'), "; echo "$filename"; copy($_FILES['images']['tmp_name'][$key], $add); chmod("$add",0777); } } $insertQuery = rtrim($insertQuery, ' ,'); SlayerACC 07-01-2010, 10:12 PM Thanks for your help... No I have not set the DB structure as of yet... I would love your input on that as well if you could. Thanks, S. Keleth 07-01-2010, 10:24 PM Well, hard to figure out what you're gonna insert if you don't know what you're inserting into :p If all you're storing is the image name, I'm not certain you need to store it into a db anyway. You could use glob to pick up all the images in a particular directory. What else do you plan on storing with the image? SlayerACC 07-01-2010, 11:23 PM I a working on a post you rig type site.. Where they post info and images of their PC and show off what they have. any help, suggestions etc. would be great. how would you go about using the glob idea.. never seen or tried it.? S. Keleth 07-01-2010, 11:45 PM Glob is a function that pulls all the files in a perticular folder, and can do what I guess would be called rudimentary regex? http://net.tutsplus.com/tutorials/php/quick-tip-loop-through-folders-with-phps-glob/ SlayerACC 07-02-2010, 08:03 PM That is awesome... Thanks very much. S. |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum