mikefrederick Posted October 9, 2007 Share Posted October 9, 2007 help please, this is the second time I posted this, I can't figure out how to upload multiple files. I have the form w/ 2 upload fields called image1 and image2. Then I am using this script which will upload the file names to a database and it will upload the first file to a folder on the site called "propertyimages/" and I need to know how to make the script also copy the other file to the folder. here is the script, which contains some additional information being submitted to the db: <?php require_once "connect.php"; $filename = $HTTP_POST_FILES['image1']['name']; $filenametwo = $HTTP_POST_FILES['image2']['name']; $path= "../propertyimages/".$filename; $pathtwo= "../propertyimages/".$filenametwo; if (copy($HTTP_POST_FILES['image1']['tmp_name'], $path)) { $addname = $_POST['Addname']; $addemail = $_POST['Addemail']; $addphone = $_POST['Addphone']; $adddesc = $_POST['Adddesc']; $addact = $_POST['Addact']; $addrates = $_POST['Addrates']; $addamen = $_POST['Addamen']; mysql_select_db($database_localhost, $localhost); $query = "INSERT INTO addnew (addname,addemail,addphone,adddesc,addamen,addact,addrates,imageone,imagetwo) VALUES('$addname','$addemail','$addphone','$adddesc','$addamen','$addact','$addrates','$filename','$filenametwo')"; $Rs = mysql_query($query, $localhost) or die(mysql_error()); Header ('Location:index.php'); } ?> Quote Link to comment Share on other sites More sharing options...
zq29 Posted October 9, 2007 Share Posted October 9, 2007 You're copying the first one with: copy($HTTP_POST_FILES['image1']['tmp_name'], $path) You need to do the same with the second one, are you learning from an old book/tutorial? You're using some depreciated methods... Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted October 9, 2007 Author Share Posted October 9, 2007 could you show on the script how to insert that because i get errors every time that i try? Quote Link to comment Share on other sites More sharing options...
zq29 Posted October 10, 2007 Share Posted October 10, 2007 This isn't the ideal way, but it should work. <?php require_once "connect.php"; $filename = $HTTP_POST_FILES['image1']['name']; $filenametwo = $HTTP_POST_FILES['image2']['name']; $path= "../propertyimages/".$filename; $pathtwo= "../propertyimages/".$filenametwo; if (copy($HTTP_POST_FILES['image1']['tmp_name'], $path) && copy($HTTP_POST_FILES['image2']['tmp_name'], $pathtwo)) { $addname = $_POST['Addname']; $addemail = $_POST['Addemail']; $addphone = $_POST['Addphone']; $adddesc = $_POST['Adddesc']; $addact = $_POST['Addact']; $addrates = $_POST['Addrates']; $addamen = $_POST['Addamen']; mysql_select_db($database_localhost, $localhost); $query = "INSERT INTO addnew (addname,addemail,addphone,adddesc,addamen,addact,addrates,imageone,imagetwo) VALUES('$addname','$addemail','$addphone','$adddesc','$addamen','$addact','$addrates','$filename','$filenametwo')"; $Rs = mysql_query($query, $localhost) or die(mysql_error()); Header ('Location:index.php'); } ?> Quote Link to comment Share on other sites More sharing options...
d22552000 Posted October 10, 2007 Share Posted October 10, 2007 *bump* please mark this as solved if it is 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.