brucensal Posted December 17, 2007 Share Posted December 17, 2007 Hi, I have finally got my file uploadscript working but now i want to modify it so i dont have to create muliple upload forms. I want to be able to upload images to my server from a form (which i can) but i want to be able to handle max of 12, which i think i have a handle on now but i want to be able to use the same form and script to upload say 2 images insterad. Is this possible? At the moment i am only playing with 2 files, but if i leave one out the script fails and does not upload the single file. Can anyone advise how i can fix this, if it can be fixed, otherwise i will haver to make multipkle upload forms and scripts to handle each number of uploads. Code below: <?PHP $uploadDir = "orderimages/"; if(isset($_POST['upload'])) { $fileName = $_FILES['mugimage1']['name']; $tmpName = $_FILES['mugimage1']['tmp_name']; $fileSize = $_FILES['mugimage1']['size']; $fileType = $_FILES['mugimage1']['type']; $fileName2 = $_FILES['mugimage2']['name']; $tmpName2 = $_FILES['mugimage2']['tmp_name']; $fileSize2 = $_FILES['mugimage2']['size']; $fileType2 = $_FILES['mugimage2']['type']; $cust_name = $_POST['cust_name']; $cust_email = $_POST['cust_email']; $mugtext = $_POST['mugtext']; $textcolour = $_POST['textcolour']; $ebayid = $_POST['ebayid']; $filePath = $uploadDir . $fileName; $filePath2 = $uploadDir . $fileName2; if (!is_writeable("$uploadDir")){ die ("The directory <b>($upload_dir)</b> is NOT writable, Please CHMOD (777)"); } if (move_uploaded_file($_FILES['mugimage1']['tmp_name'],$uploadDir.$fileName)) { //tell the user that the file has been uploaded and make him a link. echo "File (<a href=$uploadDir$fileName>$fileName</a>) uploaded!<br><br></a>"; } // print error if there was a problem moving file. else { //Print error msg. echo "There was a problem saving your logo.</a>"; exit(); } if (move_uploaded_file($_FILES['mugimage2']['tmp_name'],$uploadDir.$fileName2)) { //tell the user that the file has been uploaded and make him a link. echo "File (<a href=$uploadDir$fileName2>$fileName2</a>) uploaded!<br><br></a>"; } // print error if there was a problem moving file. else { //Print error msg. echo "There was a problem saving your logo.</a>"; exit(); } } $dbh=mysql_connect ("localhost", "*****", "******") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("******"); //////////////////////////////////////////////// //////////////////////////////////////////////// ///////DO NOT CHANGE//////////////////////////// //////////////////////////////////////////////// $query = "INSERT INTO upload (fname, size, type, fname2, size2, type2, cust_name, cust_email, mugtext, textcolour, ebayid, path, path2 ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$fileName2', '$fileSize2', '$fileType2', '$cust_name', '$cust_email', '$mugtext', '$textcolour', '$ebayid','$filePath','$filePath2')"; mysql_query($query) or die('Error, query failed'); mysql_close($dbh); echo "<br>Files Uploaded<br>"; ?> Thanks in advance Quote Link to comment Share on other sites More sharing options...
corbin Posted December 17, 2007 Share Posted December 17, 2007 http://www.php.net/features.file-upload Example 3 should help you. Quote Link to comment Share on other sites More sharing options...
brucensal Posted December 17, 2007 Author Share Posted December 17, 2007 Thanks i will take a loo at it Quote Link to comment 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.