I made an email form for my site, where I want customers to be able to send me a file from their computer.
There's a number of fields (name, email etc.) which are processing through to my email just fine.
I want to be able to receive their attachment, either as an attachment to my email, or to FTP it to my server, whichever is more straight forward for me to do.
I have the form completed, and the field where they choose and select their file. Here's what I "don't" quite get ... what type of instructions to I need in the PHP, so their file ends up coming to me.
Here is part of my code:
if (isset($_POST['sendnow']))
{
$from = $_POST['fromemail'];
$fromname = $_POST['fromname'];
$frompaypalemail = $_POST['frompaypalemail'];
$file = $_POST['file'];
$tel = $_POST['tel'];
$message = $_POST['message'];
// extra info to add to message
$address = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$ip = gethostbyname($_SERVER['REMOTE_ADDR']);
$timestamp = time ();
$filename = $_SERVER['PHP_SELF'];
$location = $_SERVER['SERVER_NAME'].$filename;
// adding
$messagewithinfo = "$message\n\n$fromemail\n\n$fromname\n\n$frompaypal email\n\n$tel\n\n\n\nAdditional info:\nIP = $ip\nAddress = $address\nTime at server = $timestamp\nSent with this page = $location\n";
mail($to, $subject, $messagewithinfo, "From: $fromname <$fromemail>\r\n" . "Reply-To: $from\r\n" . "X-Mailer: PHP/" . phpversion());
echo("$confirm");
}
else
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="emailform">
php.net has the following script for php_put
PHP Code:
<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($conn_id);
?>
Can it be incorporated into what I have done is it part of the submit on the form? And is there a variable to tell it what FOLDER to save into?