shadiadiph Posted May 9, 2009 Share Posted May 9, 2009 Just wondering if anyone can tell me how to make this work currently it uploads to the first location fine but not to the second? I tried splitting it into two foreach loops but would not work either? foreach ($_FILES["fileatt"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $fileatt = $_FILES['fileatt']['tmp_name'][$key]; $fileatt_type = $_FILES['fileatt']['type'][$key]; $fileatt_name = $_FILES['fileatt']['name'][$key]; move_uploaded_file($fileatt, "./secure/mail/$username/$savemailid/$fileatt_name"); move_uploaded_file($fileatt, "./secure/mail/$touser/$sendmailid/$fileatt_name"); } } Quote Link to comment https://forums.phpfreaks.com/topic/157516-solved-file-upload-problem/ Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 After the first move_uploaded_file() you've moved the uploaded file (as the name would imply) so it's no longer in the originaly stored directory $fileatt Take a look at http://uk3.php.net/copy That way you can take the newly uploaded file (./secure/mail/$username/$savemailid/$fileatt_name) and copy it to the second destination (./secure/mail/$touser/$sendmailid/$fileatt_name) Quote Link to comment https://forums.phpfreaks.com/topic/157516-solved-file-upload-problem/#findComment-830474 Share on other sites More sharing options...
shadiadiph Posted May 9, 2009 Author Share Posted May 9, 2009 mm thanks just tried this but it doesn't seem to be working I am getting the error Warning: Wrong parameter count for copy() foreach ($_FILES["fileatt"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $fileatt = $_FILES['fileatt']['tmp_name'][$key]; $fileatt_type = $_FILES['fileatt']['type'][$key]; $fileatt_name = $_FILES['fileatt']['name'][$key]; move_uploaded_file($fileatt, "./secure/mail/$username/$savemailid/$fileatt_name"); copy("./secure/mail/$username/$savemailid/", "./secure/mail/$touser/$sendmailid/",$fileatt_name); } } Quote Link to comment https://forums.phpfreaks.com/topic/157516-solved-file-upload-problem/#findComment-830509 Share on other sites More sharing options...
shadiadiph Posted May 9, 2009 Author Share Posted May 9, 2009 it ok I got it thanks for help gevans Quote Link to comment https://forums.phpfreaks.com/topic/157516-solved-file-upload-problem/#findComment-830524 Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 If you look at the link I gave you copy() only takes three parameters, you've passed three, but I think you just mixed up a comma and a period. Also I think you're source and destination paths are the wrong way round. bool copy ( string $source , string $dest [, resource $context ] ) <?php if(copy("./secure/mail/$touser/$sendmailid/".$fileatt_name, "./secure/mail/$username/$savemailid/")) { //it copied } else { //it failed } EDIT, cool Quote Link to comment https://forums.phpfreaks.com/topic/157516-solved-file-upload-problem/#findComment-830525 Share on other sites More sharing options...
shadiadiph Posted May 9, 2009 Author Share Posted May 9, 2009 here was the answer just for your record foreach ($_FILES["fileatt"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $fileatt = $_FILES['fileatt']['tmp_name'][$key]; $fileatt_type = $_FILES['fileatt']['type'][$key]; $fileatt_name = $_FILES['fileatt']['name'][$key]; move_uploaded_file($fileatt, "./secure/mail/$username/$savemailid/$fileatt_name"); copy("./secure/mail/$username/$savemailid/$fileatt_name", "./secure/mail/$touser/$sendmailid/$fileatt_name"); } } Quote Link to comment https://forums.phpfreaks.com/topic/157516-solved-file-upload-problem/#findComment-830528 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.