daebat Posted January 6, 2010 Share Posted January 6, 2010 I have this script which starts with a form asking for title and thumbnail. It then uploads the image to my upload folder and stores the name in the database (as well as storing the title with an ID). How can I modify this script to allow for me to upload multiple files to the database at once? Form: <form method="post" action="upload_process2.php" enctype="multipart/form-data"> <p> Title: </p> <input type="text" name="title"/> <p> Thumbnail: </p> <input type="file" name="thumb"> <br/> <br/> <input TYPE="submit" name="upload" title="Add data to the Database" value="Submit"/> </form> Processing Code: <?php echo "<pre>"; echo "FILES:"; print_r($_FILES); echo "</pre>"; $target = "path/for/upload/"; $target = $target . basename( $_FILES['thumb']['name']); $title=$_POST['title']; $thumb=($_FILES['thumb']['name']); mysql_connect("localhost", "user", "pw") or die(mysql_error()) ; mysql_select_db("database") or die(mysql_error()) ; mysql_query("INSERT INTO test2 (title,thumb) VALUES ('$title', '$thumb')") ; if(move_uploaded_file($_FILES['thumb']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { echo "Sorry, there was a problem uploading your file."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/187457-help-me-modify-my-script/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2010 Share Posted January 6, 2010 I would use HTML array variables. See Example #3 at this link - http://us.php.net/manual/en/features.file-upload.post-method.php Quote Link to comment https://forums.phpfreaks.com/topic/187457-help-me-modify-my-script/#findComment-989842 Share on other sites More sharing options...
PHP Monkeh Posted January 6, 2010 Share Posted January 6, 2010 Do you want to upload multiple thumbnails associated with the same title, or is one title associated with one thumbnail and you want to be able to submit many from one page? If the first, change the name of your file field from "thumb" to "thumb[]". This will allow you to them loop through the multiple fields like so: <?php foreach($_FILES['thumb']['name'] as $key) { move_uploaded_file($_FILES['thumb']['tmp_name'][$key], $target); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/187457-help-me-modify-my-script/#findComment-989847 Share on other sites More sharing options...
daebat Posted January 6, 2010 Author Share Posted January 6, 2010 Do you want to upload multiple thumbnails associated with the same title, or is one title associated with one thumbnail and you want to be able to submit many from one page? Well I am going to need to use 1 title, 1 thumbnail, 1 full sized jpg of the thumbnail (so i suppose it could be resized with html), 1 tiff, and 1 png. (the site is for franchisees to get marketing materials so I need for our graphic designer to be able to upload several different types of the same file. After I get all of this figured out, I'm going to have to figure out a way to pull the files for display and download. Quote Link to comment https://forums.phpfreaks.com/topic/187457-help-me-modify-my-script/#findComment-989860 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.