PHP Upload file problem in my Contact form
Posted: Fri Aug 08, 2014 10:53 pm
I have a problem when I am going to edit the PHP code I want it to send the attachment file to the folder in my server
This is the HTML Code**
<p><label>
<input id="file" name="file" size="20" type="file" value="" action="mailer.php" method="POST" dir="ltr" />
</label></p>
And this is the PHP CODE :
I want that file attached stored in my Server
I hope to find a solution
This is the HTML Code**
<p><label>
<input id="file" name="file" size="20" type="file" value="" action="mailer.php" method="POST" dir="ltr" />
</label></p>
And this is the PHP CODE :
Code: Select all
<?php
/* Set e-mail recipient */
$myemail = "info@elitetranslingo.com";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$subject = check_input($_POST['subject'], "Enter a subject");
$email = check_input($_POST['email']);
$phone = check_input($_POST['phone']);
$source= check_input($_POST['source']);
$targetlang= check_input($_POST['targetlang']);
$file= check_input($_POST['file']);
$message = check_input($_POST['message'], "Write your message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
E-mail: $email
Phone: $phone
Source Language: $source
Target Language: $targetlang
Attach File: $file
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: confirmation.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
I hope to find a solution