feri_soft Posted August 31, 2006 Share Posted August 31, 2006 Hi,I need a multiple file upload script that have for example 5 fields and can only allow gif and jpg to be uploaded.Another very important thing is to have db support so the data of the files can be stored in db data such as... filename,size and file_id...I created a solution for this but only for single file upload...but for multiple!?Thank you!p.sI found this on the web but i cant figure it out how to create a db support for it:[code]<?php/* Handle multiple file upload easily *//* by Ronny Haryanto <[email protected]> *//* February-ish 1999 *//* Use it however you want. I'm not responsible for what you do with it. *//* how many upload slots? */define("UPLOAD_SLOTS", 5);/* where to move the uploaded file(s) to? */define("INCOMING", "/home/ronny/incoming/");if($REQUEST_METHOD!="POST"){ /* generate form */ echo "<form enctype=\"multipart/form-data\" method=post>\n"; for($i=1; $i<=UPLOAD_SLOTS; $i++) { echo "<input type=file name=infile$i><br>\n"; } echo "<input type=submit value=upload></form>\n";}else{ /* handle uploads */ $noinput = true; for($i=1; $noinput && ($i<=UPLOAD_SLOTS); $i++) { if(${"infile".$i}!="none") $noinput=false; } if($noinput) { echo "error uploading. create 150MB coredump instead?"; exit(); } for($i=1; $i<=UPLOAD_SLOTS; $i++) { if(${"infile".$i}!="none" && copy(${"infile".$i}, INCOMING.${"infile".$i."_name"}) && unlink(${"infile".$i})) { echo ${"infile".$i."_name"}." uploaded<br>"; } }} /* else */?>[/code] Link to comment https://forums.phpfreaks.com/topic/19272-multiple-upload-with-db-support/ Share on other sites More sharing options...
onlyican Posted August 31, 2006 Share Posted August 31, 2006 on the form, have<input type='file' name='infile[]' />This makes them an arraythen loop through the array Link to comment https://forums.phpfreaks.com/topic/19272-multiple-upload-with-db-support/#findComment-83575 Share on other sites More sharing options...
jpratt Posted August 31, 2006 Share Posted August 31, 2006 go to:http://us3.php.net/manual/en/features.file-upload.phphas an example of uploading an array of files. Link to comment https://forums.phpfreaks.com/topic/19272-multiple-upload-with-db-support/#findComment-83581 Share on other sites More sharing options...
feri_soft Posted September 1, 2006 Author Share Posted September 1, 2006 Ok i found this but how to create db support for it:<form action="" method="post" enctype="multipart/form-data"><p>Pictures:<input type="file" name="pictures[]" /><input type="file" name="pictures[]" /><input type="file" name="pictures[]" /><input type="submit" value="Send" /></p></form><?phpforeach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "data/$name"); }}?> Link to comment https://forums.phpfreaks.com/topic/19272-multiple-upload-with-db-support/#findComment-83856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.