amrita Posted September 18, 2008 Share Posted September 18, 2008 $file_field_name = "file";$submit_field_name = "upload";$upload_dir = "attach/";if (isset($_POST[$submit_field_name])){ # Check if there is a file if (is_uploaded_file($_FILES[$file_field_name]["tmp_name"])){ if (move_uploaded_file($_FILES[$file_field_name]["tmp_name"], $upload_dir.basename($_FILES[$file_field_name]["name"]))){ $filename = basename($_FILES[$file_field_name]["name"]); echo "File successfully attached:<br /><br /> $filename <img src=\"".$upload_dir."/".$filename."\"><br /><br />"; }else{ echo "There were some errors!"; } }}# There's random server info here and stuff# There's random server info here and stuff# There's random server info here and stuff# There's random server info here and stuff$message = new Mail_mime();$message->setTXTBody($text);$message->setHTMLBody($html);$message->addAttachment("What do I type here to make it use the latest uploaded file and send it along with the email");---I cannot seem to make it send the attachment with the email, it simply uploads the file to a folder, which is not what I want.Can anyone help? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2008 Share Posted September 18, 2008 It needs to upload the file before it can attach it to anything. I'm sure you probably just put the filename that you want to attach into the addAttachment method, but you can check the documentation for that to find out for sure. The filename after it gets moved is: $upload_dir.basename($_FILES[$file_field_name]["name"] Link to comment Share on other sites More sharing options...
amrita Posted September 18, 2008 Author Share Posted September 18, 2008 I get an error message - unexpected T_VARIABLE if I insert what you wrote - what am I doing wrong? I am supposed to put it here right:$message->addAttachment($upload_dir.basename($_FILES[$file_field_name]["name"]);or? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2008 Share Posted September 18, 2008 I missed a paren, that needs a closing paren on the end of it (there are 2 opening and 1 closing). Link to comment Share on other sites More sharing options...
amrita Posted September 18, 2008 Author Share Posted September 18, 2008 Thank you, but now I get a new problem: Warning: fopen(attach/): failed to open stream: Permission denied in **************\PEAR\Mail\mime.php on line 385Now, what's this? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2008 Share Posted September 18, 2008 Permission denied means you don't have permission to open the file. Add a line after the if statement to set permissions.if (move_uploaded_file($_FILES[$file_field_name]["tmp_name"], $upload_dir.basename($_FILES[$file_field_name]["name"]))){chmod($upload_dir.basename($_FILES[$file_field_name]["name"]), 0644); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.