Retrieving a file name to attach to an email with SwiftMailer and PHP -


Text after "

I asked the question yesterday and have one advice, and use it, but it does not work for some reason. Therefore, I need to retrieve the name of the file that was uploaded to my server by a server from the HTML server. I need this file to be attached to the email sent by PHP / Swift Mailer. Here is my code upload file:

  // file upload // where file is going $ $ Target_path to be placed = "upload /"; // Add the original file name to our target path. // result "upload / file name extension" is $ target_path = $ target_path. Basename ($ _FILES ['Uploaded file'] ['name']); If (move_uploaded_file ($ _ FILES ['uploadfile'] ['tmp_name'], $ target_path)) {resonant "file" basename ($ _FILES ['uploaded file'] ['name']). "Uploaded"; } Else {echo "There was an error uploading the file, please try again!"; } // File End Upload  

This file is an attached part:

  // Add attachment $ attachment = Swift_Attachment :: fromPath ($ _ files [ 'Uploadedfile'] ['tmp_name']);  

Why did not it get the file from the server? The error message is, and it looks like it is trying to find the file in a wrong directory:

WARNING: fopen (/ tmp / phpHJdw0H) [function.fopen] : The stream failed to open: Line 131 on a serious error such a file or directory at /home/myserver/mydomain.com/Hawaii/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php: Message Unable to come up with 'Swift_IoException' 'Exception # 0 etc.

Thanks!

Use:

  $ attachment = swift_attachment :: from path ($ Target route);  

The reason for this is that you have moved the file from your temporary location, $ _ FILES ['uploadfile'] ['tmp_name'] moved to your Before the path comes back, the file assumes that $ target_path is within the scope of the fast mailer code


Comments