Jump to content

Simple Lack of Knowledge


ScottAllenNet

Recommended Posts

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

You must make sure that the file is uploaded properly. Your error shows "There was an error uploading the file, please try again!".

 

Ok so I just tried again and got this issue:

 

There was an error uploading the file, please try again!
Fatal error: Call to undefined function mime_content_type() in /homepages/7/d393500880/htdocs/harrisonpearce/_layout/php/submit-cv.php on line 70

 

By the way - thanks again for all of your help.

 

Scott.

Link to comment
Share on other sites

That's the exact same thing. Make sure you have the folder called upload. Your script is not uploading the file as there was an error uploading it. Try small files.

 

Ok so keep getting this error:

 

There was an error uploading the file, please try again!
Fatal error: Call to undefined function mime_content_type() in /homepages/7/d393500880/htdocs/harrisonpearce/_layout/php/submit-cv.php on line 70

 

I have tried smaller files etc. Really confused.

 

I have got the uploads folder in the same place as the php file.

Link to comment
Share on other sites

Okay, try this code

 

<?php

// upload the file to the server

$filename = basename( $_FILES['attachcv']['name']);


// Where the file is going to be placed
$target_path = "uploads/";


/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['attachcv']['name']); 


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


$file = file_get_contents($target_path);


// get posted data into local variables
$EmailFrom = "website@harrisonpearce.com";
$EmailTo = "register@harrisonpearce.com";
$Subject = "New Candidate Registration";
$name = Trim(stripslashes($_POST['name'])); 
$email = Trim(stripslashes($_POST['email'])); 
$telephone = Trim(stripslashes($_POST['telephone'])); 
$location = Trim(stripslashes($_POST['location'])); 
$coveringletter = Trim(stripslashes($_POST['coveringletter'])); 


// validation
$validationOK=true;
if (Trim($name)=="") $validationOK=false;
if (Trim($email)=="") $validationOK=false;
if (Trim($telephone)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
  exit;
}


// prepare email body text
$Body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n"
$Body .= "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $telephone;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $location;
$Body .= "\n";
$Body .= "Covering Letter: ";
$Body .= $coveringletter;
$Body .= "\n";
$Body .= "Content-Type: ".mime_content_type($file)."; name=\"" .$target_path. "\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-disposition: attachment; file=\"" .$target_path. "\"\r\n" . "\r\n" . chunk_split(base64_encode($file));




// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");


// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../sent\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
}
?>

Link to comment
Share on other sites

Okay let's try this out. Create a new html file and name it testform.html and insert the following codes

 

<form name="submit-cv" id="submit-cv" action="uploadtest.php" method="post">


<table>
<tbody><tr>
	<td>
		Your Name: <font color="#DA1623">*</font><br />
		<input id="name" class="text" type="text" value="" name="name">
	</td>
	<td>
		Email Address: <font color="#DA1623">*</font><br />
		<input id="email" class="text" type="text" value="" name="email">
	</td>
</tr>
<tr>
	<td>
		Telephone: <font color="#DA1623">*</font><br />
		<input id="telephone" class="text" type="text" value="" name="telephone">
	</td>
	<td>
		Location:<br />
		<input id="location" class="text" type="text" value="" name="location">
	</td>
</tr>

<tr>
	<td colspan="2">
		Attach CV:<br />
		<input type="file" name="attachcv" id="attachcv" /> 
	</td>
</tr>
<tr>
	<td colspan="2">
		Covering Letter/Other:<br />
		<textarea name="coveringletter" rows="5" cols="20"></textarea>
	</td>
</tr>
</tbody></table>

<input type="submit" name="submit" value="Send Details">

</form>

 

also in the same folder, create a php file and name it uploadtest.php and insert the following code

 

<?php

// upload the file to the server

$filename = basename( $_FILES['attachcv']['name']);


// Where the file is going to be placed
$target_path = "uploads/";


/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['attachcv']['name']); 


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


$file = file_get_contents($target_path);


// get posted data into local variables
$EmailFrom = "website@harrisonpearce.com";
$EmailTo = "register@harrisonpearce.com";
$Subject = "New Candidate Registration";
$name = Trim(stripslashes($_POST['name'])); 
$email = Trim(stripslashes($_POST['email'])); 
$telephone = Trim(stripslashes($_POST['telephone'])); 
$location = Trim(stripslashes($_POST['location'])); 
$coveringletter = Trim(stripslashes($_POST['coveringletter'])); 


// validation
$validationOK=true;
if (Trim($name)=="") $validationOK=false;
if (Trim($email)=="") $validationOK=false;
if (Trim($telephone)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
  exit;
}


// prepare email body text
$Body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n";
$Body .= "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $telephone;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $location;
$Body .= "\n";
$Body .= "Covering Letter: ";
$Body .= $coveringletter;
$Body .= "\n";
$Body .= "Content-Type: ".mime_content_type($file)."; name=\"" .$target_path. "\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-disposition: attachment; file=\"" .$target_path. "\"\r\n" . "\r\n" . chunk_split(base64_encode($file));




// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");


// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../sent\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
}
?>

 

test out the form and what do you get?

Link to comment
Share on other sites

Okay let's try this out. Create a new html file and name it testform.html and insert the following codes

 

<form name="submit-cv" id="submit-cv" action="uploadtest.php" method="post">


<table>
<tbody><tr>
	<td>
		Your Name: <font color="#DA1623">*</font><br />
		<input id="name" class="text" type="text" value="" name="name">
	</td>
	<td>
		Email Address: <font color="#DA1623">*</font><br />
		<input id="email" class="text" type="text" value="" name="email">
	</td>
</tr>
<tr>
	<td>
		Telephone: <font color="#DA1623">*</font><br />
		<input id="telephone" class="text" type="text" value="" name="telephone">
	</td>
	<td>
		Location:<br />
		<input id="location" class="text" type="text" value="" name="location">
	</td>
</tr>

<tr>
	<td colspan="2">
		Attach CV:<br />
		<input type="file" name="attachcv" id="attachcv" /> 
	</td>
</tr>
<tr>
	<td colspan="2">
		Covering Letter/Other:<br />
		<textarea name="coveringletter" rows="5" cols="20"></textarea>
	</td>
</tr>
</tbody></table>

<input type="submit" name="submit" value="Send Details">

</form>

 

also in the same folder, create a php file and name it uploadtest.php and insert the following code

 

<?php

// upload the file to the server

$filename = basename( $_FILES['attachcv']['name']);


// Where the file is going to be placed
$target_path = "uploads/";


/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['attachcv']['name']); 


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


$file = file_get_contents($target_path);


// get posted data into local variables
$EmailFrom = "website@harrisonpearce.com";
$EmailTo = "register@harrisonpearce.com";
$Subject = "New Candidate Registration";
$name = Trim(stripslashes($_POST['name'])); 
$email = Trim(stripslashes($_POST['email'])); 
$telephone = Trim(stripslashes($_POST['telephone'])); 
$location = Trim(stripslashes($_POST['location'])); 
$coveringletter = Trim(stripslashes($_POST['coveringletter'])); 


// validation
$validationOK=true;
if (Trim($name)=="") $validationOK=false;
if (Trim($email)=="") $validationOK=false;
if (Trim($telephone)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
  exit;
}


// prepare email body text
$Body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n"
$Body .= "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $telephone;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $location;
$Body .= "\n";
$Body .= "Covering Letter: ";
$Body .= $coveringletter;
$Body .= "\n";
$Body .= "Content-Type: ".mime_content_type($file)."; name=\"" .$target_path. "\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-disposition: attachment; file=\"" .$target_path. "\"\r\n" . "\r\n" . chunk_split(base64_encode($file));




// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");


// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../sent\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
}
?>

 

test out the form and what do you get?

 

 

On testing the form I get this:

 

There was an error uploading the file, please try again!
Fatal error: Call to undefined function mime_content_type() in /homepages/7/d393500880/htdocs/harrisonpearce/test/uploadtest.php on line 68

 

http://harrisonpearce.com/test/testform.html

Link to comment
Share on other sites

I beleive the error lies with this code:

 

$Body .= "Content-Type: ".mime_content_type($file)."; name=\"" .$target_path. "\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-disposition: attachment; file=\"" .$target_path. "\"\r\n" . "\r\n" . chunk_split(base64_encode($file));

 

On line 68.

Link to comment
Share on other sites

Okay let's start from scratch. So firstly we need a form with a file upload function.

 

<form enctype="multipart/form-data" name="submit-cv" id="submit-cv" action="uploadtest.php" method="post">
<table>
   <tbody>
      <tr>
         <td>
            Your Name: <font color="#DA1623">*</font><br />
            <input id="name" class="text" type="text" value="" name="name">
         </td>
         <td>
            Email Address: <font color="#DA1623">*</font><br />
            <input id="email" class="text" type="text" value="" name="email">
         </td>
      </tr>
      <tr>
         <td>
            Telephone: <font color="#DA1623">*</font><br />
            <input id="telephone" class="text" type="text" value="" name="telephone">
         </td>
         <td>
            Location:<br />
            <input id="location" class="text" type="text" value="" name="location">
         </td>
      </tr>

      <tr>
         <td colspan="2">
            Attach CV:<br />
            <input name="attachcv" id="file" type="file" /> 
         </td>
      </tr>
      <tr>
         <td colspan="2">
            Covering Letter/Other:<br />
            <textarea name="coveringletter" rows="5" cols="20"></textarea>
         </td>
      </tr>
   </tbody>
</table>

<input type="submit" name="submit" value="Send Details">

</form>

 

Next verify if our form is working. I'm just going to echo out the data and upload the file.

 

<?php

// here we check if the file is being attached and then upload it to the server
if($_FILES['attachcv']['name']) {

	$target_path = "";

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

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


// here we get the data from the form
$name = Trim(stripslashes($_POST['name'])); 
$email = Trim(stripslashes($_POST['email'])); 
$telephone = Trim(stripslashes($_POST['telephone'])); 
$location = Trim(stripslashes($_POST['location'])); 
$coveringletter = Trim(stripslashes($_POST['coveringletter'])); 

// here we echo out the data received
echo $name ."</br>";
echo $email."</br>";
echo $telephone."</br>";
echo $location."</br>";
echo $coveringletter."</br>";
echo mime_content_type($_FILES['attachcv']['name']);
?>

 

 

Okay, try this out. I've tested it and it's working. If it's not working in your end, there might be some server problems.

Link to comment
Share on other sites

Ok,

 

so when I run this I get the following:

 

The file Ethics Approval Form.docx has been uploaded
Scott Allen
mail.scottallen@gmail.com
447867616540
United Kingdom


Fatal error: Call to undefined function mime_content_type() in /homepages/7/d393500880/htdocs/harrisonpearce/test/uploadtest.php on line 39

 

The file upload ends up in the same directory as the php and html files in http://harrisonpearce.com/test not in the uploads folder.

 

No email is sent.

 

 

Link to comment
Share on other sites

Do you even read the codes or you just blatantly copy and run it?

1) Of course it is uploaded in the same directory! I have it targeted to the same folder and the php & html.

2) No email is sent cause I've not added the mail sent function.

 

I wonder if I'm doing all this coding for you and you're just there copying and pasting and running the codes. Do you even know the fundamentals of PHP?

Link to comment
Share on other sites

I am reading the code I asure you I was merely commenting on what the script has produced just to confirm that it falls inline with what we are trying to achieve.

 

I am not rude enough to ignore the work you are putting in - and I really appreciate it. I am learning allot!

Link to comment
Share on other sites

okay. it seems that your mime_content_type is disabled. the script works well on my server.

try this code.

 

<?php

   error_reporting(E_ALL);
   ini_set('display_errors', '1');
   
   // here we check if the file is being attached and then upload it to the server
   if($_FILES['attachcv']['name']) {
      
      $target_path = "";

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

      if(move_uploaded_file($_FILES['attachcv']['tmp_name'], $target_path)) {
         echo "The file ".  basename( $_FILES['attachcv']['name']). 
         " has been uploaded";
         echo "</br>";
      }
      else{
         echo "There was an error uploading the file, please try again!";
         echo "</br>";
      }
   }
   else{
      echo "The file is not attached!";
      echo "</br>";
   }
   
   
   // here we get the data from the form
   $name = Trim(stripslashes($_POST['name'])); 
   $email = Trim(stripslashes($_POST['email'])); 
   $telephone = Trim(stripslashes($_POST['telephone'])); 
   $location = Trim(stripslashes($_POST['location'])); 
   $coveringletter = Trim(stripslashes($_POST['coveringletter'])); 
   $file = $_FILES['attachcv']['name'];

   // validate the data
   $validationOK=true;
   if (Trim($name)=="") $validationOK=false;
   if (Trim($email)=="") $validationOK=false;
   if (Trim($telephone)=="") $validationOK=false;
   if (!$validationOK) {
      echo "Error on validation! Please fill in all the required info.";
      exit;
   }

   // here we echo out the data received
   echo $name ."</br>";
   echo $email."</br>";
   echo $telephone."</br>";
   echo $location."</br>";
   echo $coveringletter."</br>";
   echo mime_content_type($file);

?>

Link to comment
Share on other sites

Thanks buddy.

 

Ok so, ran that updated one.

 

The file CV.docx has been uploaded
Scott Allen
mail.scottallen@gmail.com
447867616540
United Kingdom
Test

Fatal error: Call to undefined function mime_content_type() in /homepages/7/d393500880/htdocs/harrisonpearce/test/uploadtest.php on line 53

Link to comment
Share on other sites

okay, it seems that mime_content_type is deprecated.

 

I've used a newer version of the function

 

<?php

   //error_reporting(E_ALL);
   //ini_set('display_errors', '1');
   
   // here we check if the file is being attached and then upload it to the server
   if($_FILES['attachcv']['name']) {
      
      $target_path = "";

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

      if(move_uploaded_file($_FILES['attachcv']['tmp_name'], $target_path)) {
         echo "The file ".  basename( $_FILES['attachcv']['name']). 
         " has been uploaded";
         echo "</br>";
      }
      else{
         echo "There was an error uploading the file, please try again!";
         echo "</br>";
      }
   }
   else{
      echo "The file is not attached!";
      echo "</br>";
   }
   
   
   // here we get the data from the form
   $name = Trim(stripslashes($_POST['name'])); 
   $email = Trim(stripslashes($_POST['email'])); 
   $telephone = Trim(stripslashes($_POST['telephone'])); 
   $location = Trim(stripslashes($_POST['location'])); 
   $coveringletter = Trim(stripslashes($_POST['coveringletter'])); 
   $file = $_FILES['attachcv']['name'];

   // validate the data
   $validationOK=true;
   if (Trim($name)=="") $validationOK=false;
   if (Trim($email)=="") $validationOK=false;
   if (Trim($telephone)=="") $validationOK=false;
   if (!$validationOK) {
      echo "Error on validation! Please fill in all the required info.";
      exit;
   }

   // here we echo out the data received
   echo $name ."</br>";
   echo $email."</br>";
   echo $telephone."</br>";
   echo $location."</br>";
   echo $coveringletter."</br>";

   // get mime type.
   $finfo = finfo_open(FILEINFO_MIME_TYPE);
   echo finfo_file($finfo, $file);

?>

Link to comment
Share on other sites

Thanks again buddy.

 

Just ran that:

 

The file Internal Recruitment CV.docx has been uploaded
Scott Allen
mail.scottallen@gmail.com
447867616540
United Kingdom
est

Fatal error: Call to undefined function finfo_open() in /homepages/7/d393500880/htdocs/harrisonpearce/test/uploadtest.php on line 55

 

Not seen this error before :/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.