A
Anonymous
Guest
hi,
i had the following code working on a windows server with php and apache:
the attachment was sending fine and being uploaded to a folder locally (uploads under htdocs)
however, when i upload the code to my live server (linux with php and apache), i can get the attachment to send, but it does not appear in the upload folder.
relevant code is as follows (the rest is unchanged):
i have tried a number of other directory paths but with no success. if i change it to, for example '/htdocs/cp/uploads', an empty file arrives via email and nothing is uploaded.
i have tried setting the permissions on uploads to 600 and 777 but that didn't help.
does anyone have any idea what might be causing this?
many thanks,
luke.
i had the following code working on a windows server with php and apache:
Code:
<?php
// set variables
error_reporting(E_ALL);
$uploaddir = 'C:/uploads//';//extra slash needed for escape char.
$newfile = $uploaddir . $_FILES['userfile']['name'];
$to ="luke@lukem.co.uk";
$subject = "Feedback from Caring-People Site";
$from = $_POST['email'];
$address = $_POST['address'];
$birth = $_POST['birth'];
$phone = $_POST['phone'];
//$message =$_POST['message'];
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$tmp_name = $_FILES['userfile']['tmp_name'];
$type = $_FILES['userfile']['type'];
$name = $_FILES['userfile']['name'];
$size = $_FILES['userfile']['size'];
//check if the file exists, then upload it and read it in to a variable for attachment.
if(file_exists($tmp_name)){
move_uploaded_file($_FILES['userfile']['tmp_name'], $newfile);
$file = fopen($newfile,'rb'); // open the file for a binary read
$data = fread($file,filesize($tmp_name)); // read the file content into a variable
fclose($file); // close the file
// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// next, we'll build the message body
// note that we insert two dashes in front of the
// MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$message .= "Application for: ".$_POST["position"] ."\n\n";
$message .= "Full Name: ".$_POST["name"] ."\n\n";
$message .= "Sender's Postal Address: ".$_POST["address"] . "\n\n";
$message .= "Phone Number: ".$_POST["phone"] . "\n\n";
$message .= "Date of Birth: ".$_POST["birth"] ."\n\n";
$message .= "Message body: ". $_POST["message"] ."\n\n";
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content and set another boundary to
// indicate that the end of the file has been reached
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
// now we just send the message
if (@mail($to, $subject, $message, $headers))
header("Location: thanks.htm");
else
header("Location: error.htm");
?>
the attachment was sending fine and being uploaded to a folder locally (uploads under htdocs)
however, when i upload the code to my live server (linux with php and apache), i can get the attachment to send, but it does not appear in the upload folder.
relevant code is as follows (the rest is unchanged):
Code:
$uploaddir = '/uploads';
$newfile = $uploaddir . $_FILES['userfile']['name'];
i have tried a number of other directory paths but with no success. if i change it to, for example '/htdocs/cp/uploads', an empty file arrives via email and nothing is uploaded.
i have tried setting the permissions on uploads to 600 and 777 but that didn't help.
does anyone have any idea what might be causing this?
many thanks,
luke.