Jump to content

Mail Form Attachment Error


Gatsu
 Share

Recommended Posts

Hello, how come I get this error with this file:Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/planetzi/public_html/man.php on line 7Error: Wrong file type!Line 7: $filedata = file_get_contents($tmp); //Get file contentsThis is how it looks in the form:<input type="file" name="sample">I attached a .JPG fileMailcode:

<?//Gather file data and other things$tmp = $_FILES['sample']['tmp_name'];$sep = md5(time());$filename = $_FILES['sample']['name'];$filedata = file_get_contents($tmp); //Get file contents$fdata = chunk_split(base64_encode($filedata)); //Encode data into text form$to = "info@gratisannons.net"; //Email address to send this to//Determine mime type$ext = explode('.', $filename);$ext = $ext[1];if($ext == "JPG" || $ext == "jpg" || $ext == "JPEG" || $ext == "jpeg") {$mime_type = "image/jpeg";}elseif($ext == "gif" || $ext == "GIF") {$mime_type = "image/gif";}else {exit("Error: Wrong file type!");}//Begin the message.  Be sure to change this how you want it.$message = "yada yada";//Begin the headers$headers = "From: \"From Name\" <{$email}>MIME-Version: 1.0Content-Type: Multipart/Mixed;  boundary=\"$sep\"charset=\"iso-8859-1\"Content-Transfer-Encoding: 7bit--$sepContent-Type: $mime_type;  name=\"$filename\"Content-Transfer-Encoding: base64Content-Disposition: attachment;	filename=\"$filename\"$fdata--$sep";$subject = "Email Subject Here";mail($to, $subject, $message, $headers);?>

Edited by Gatsu
Link to comment
Share on other sites

no it just looks like this: <form action="man.php" method="post" name="skapa" >EDIT: I fixed it by adding enctype"multipart/form-data" to the form tag. thank you very much =)

Edited by Gatsu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...