Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

upload file in form query

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

upload file in form query

Postby newtotheland » Fri Nov 02, 2012 3:01 am

I need help with html and php for upload file options for this site please. http://www.penaltysolutions.co.uk

All I want to be able to do is allow people to upload two pdf's, text files or images not exceeding 20 meg in one go which should be emailed to my site email with the other 'contact us' form info... everything works except the file uploads.

basically the name, surname etc process goes through, after you submit you get thank you for submitting reply but in top left corner it states "There was an error uploading the file, please try again!". And file is no where on directory or part of the email my admin email gets.

I have tried to code myself (in bold) but battling. Currently contact.html page looks like this:

Code: Select all
<form name="htmlform" method="post" action="html_form_send.php"enctype="multipart/form-data">
<table width="450px">
</tr>
<tr>
 <td style= "position:absolute; top:265px; left:280px">
  <label for="first_name">First Name *</label>
 </td>
 <td style= "position:absolute; top:285px; left:280px">
  <input  type="text" name="first_name" maxlength="50" size="30">
 </td>
</tr>

<tr>
 <td style= "position:absolute; top:313px; left:280px">
  <label for="last_name">Last Name *</label>
 </td>
 <td style= "position:absolute; top:333px; left:280px">
  <input  type="text" name="last_name" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td style= "position:absolute; top:356px; left:280px">
  <label for="email">Email Address *</label>
 </td>
 <td style= "position:absolute; top:376px; left:280px">
  <input  type="text" name="email" maxlength="80" size="30">
 </td>

</tr>
<tr>
 <td style= "position:absolute; top:400px; left:280px">
  <label for="comname">Company name </label>
 </td>
 <td style= "position:absolute; top:420px; left:280px">
  <input  type="text" name="comname" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td style= "position:absolute; top:356px; left:570px">
  <label for="comweb">Company website </label>
 </td>
 <td style= "position:absolute; top:376px; left:570px">
  <input  type="text" name="comweb" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td style= "position:absolute; top:400px; left:570px">
  <label for="telephone">Telephone Number *</label>
 </td>
 <td style= "position:absolute; top:420px; left:570px">
  <input  type="text" name="telephone" maxlength="30" size="30">
 </td>
</tr>
<tr>
 <td style= "position:absolute; top:446px; left:280px">
  <label for="comments">Description of circumstances *</label>
 </td>
 <td style= "position:absolute; top:469px; left:280px">
  <textarea  name="comments" maxlength="1000" cols="68" rows="6"></textarea>
[b] </td>
<td style= "position:absolute; top:272px; left:570px" enctype="multipart/form-data" action="html_form_send.php" method="POST" >
Upload file 1: <input type="file" name="uploaded file" />
</td>
 <td style= "position:absolute; top:316px; left:570px" enctype="multipart/form-data"action="html_form_send.php" method="POST" >
 Upload file 2: <input type="file" name="uploaded file" />
</td>
</tr>
<tr>
 <td style= "position:absolute; top:500px; left:930px"colspan="2" style="text-align:center">
  <input type="submit" value="Upload file"> [/b]
 </td>
</tr>
</table>
</form>


and and html_form_send.php looks like this:

Code: Select all
<?php
if(isset($_POST['email'])) {

// CHANGE THE TWO LINES BELOW
$email_to = "admin@penaltysolutions.co.uk";

                $email_subject = "New Entry";

function died($error) {
// your error code can go here
echo "We're sorry, but there are errors found with the form you submitted.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comname']) ||
!isset($_POST['comweb']) ||
!isset($_POST['comments'])){
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$comweb = $_POST['comweb'];
$comname = $_POST['comname'];

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
   $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
$string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
   $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
   $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
   $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
   died($error_message);
  }
$email_message = "Form details below.\n\n";

function clean_string($string) {
 $bad = array("content-type","bcc:","to:","cc:","href");
 return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$email_message .= "Comweb: ".clean_string($comweb)."\n";
$email_message .= "Commname: ".clean_string($comname)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
[b]$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']).
        " has been uploaded";
} else{
        echo "There was an error uploading the file, please try again!";
}[/b]
?>

<!-- place your own success html below -->

<html>
<head>
<meta charset="utf-8" />
<title>Penalty Solutions Uk</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>
<body>
<div id="header">
<div id="logo">
<a href="index.html"><img src="images/logo.jpg" alt="" /></a>
</div>
<ul>
<li><a href="index.html"><span>home</span></a></li>
<li><a href="about.html"><span>about us</span></a></li>
<li><a href="services.html"><span>services</span></a></li>
<li><a href="products.html"><span>products</span></a></li>
<li><a href="contact us1.html"><span>contact us</span></a></li>
</ul>

</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>

<DIV style="position: absolute; top:300px; left:450px; width:900px; height:45px">Thank you for contacting us. We will be in touch with you very soon.</DIV>

<?php
}
die();
?>



any help would really be appreciated.
newtotheland
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Nov 02, 2012 2:52 am

Return to PHP coding => General

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron