I asked a question yesterday and got advice and used it, but for some reason it doesn't work. So, I need to get the name of the file that was uploaded to my server from the HTML form by the user. I need this file to be attached to the email that should be sent by PHP / SwiftMailer. Here is my code, part of the file upload:
//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 part of the file attachment:
//Create the attachment $attachment = Swift_Attachment::fromPath($_FILES['uploadedfile']['tmp_name']);
Why is he not receiving a file from the server? Here is the error message, and it looks like it is trying to find the file in the wrong directory:
Warning: fopen (/ tmp / phpHJdw0H) [function.fopen]: could not open stream: there is 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: throw a Swift_IoException exception with the 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
and etc.
Thanks!
source share