Jump to content

[SOLVED] file upload problem


shadiadiph

Recommended Posts

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"); 

   } 
}

Link to comment
https://forums.phpfreaks.com/topic/157516-solved-file-upload-problem/
Share on other sites

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)

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);



   } 
}

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 :)

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");



   } 
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.