I asked the question yesterday and got an advice, and used it, but it doesn't work for some reason. So, I need to retrieve the name of the file that was uploaded to my server from an HTML form by a user. I need this file to be attached to an email that is to be sent by PHP/SwiftMailer. Here is my code, the file upload portion:
//File upload
// Where the file is going to be placed
$target_path = "uploads/";
// Add the original filename to our target path.
//Result is "uploads/filename.extension"
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
//End of file upload
This is the file attaching portion:
//Create the attachment
$attachment = Swift_Attachment::fromPath($_FILES['uploadedfile']['tmp_name']);
Why doesn't it get the file from the server? Here is the error message, and it looks like it's trying to find the file in a wrong directory:
Warning: fopen(/tmp/phpHJdw0H) [function.fopen]: failed to open stream: No such file or directory in /home/myserver/mydomain.com/Hawaii/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php on line 131 Fatal error: Uncaught exception 'Swift_IoException' with message 'Unable to open file for reading [/tmp/phpHJdw0H]' in /home/myserver/mydomain.com/Hawaii/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php:133 Stack trace: #0
etc.
Thank you!