ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 It's unable to call the mime_content_type() because the file has an error in uploading. If the file is not uploaded, the script is not able to call what type of file is being uploaded. Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 It's unable to call the mime_content_type() because the file has an error in uploading. If the file is not uploaded, the script is not able to call what type of file is being uploaded. Â Ok I see. Do you know how to correct this then? Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 You must make sure that the file is uploaded properly. Your error shows "There was an error uploading the file, please try again!". Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 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. Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 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. Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 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. Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 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\">"; } ?> Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 Ok cheers dude - pulling up this error now: Â 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 68 Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 How did your get this error? did you fill out the form and try it? Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 Yes - I filled out all parts of the form and tried it: Â See: http://www.harrisonpearce.com/submit-your-cv Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 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? Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 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 Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 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. Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 the error doesn't lie on that. there was an error uploading the file thus the mime content type could not get the file. Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 I have tried a few different files and get the same error every time :/ Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 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. Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 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. Â Â Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 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? Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 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! Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 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); ?> Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 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 Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 24, 2012 Share Posted June 24, 2012 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); ?> Quote Link to comment Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 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 :/ Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 27, 2012 Share Posted June 27, 2012 Do you have access to the php.ini? It seems like most of the features you need are disabled :/ Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 27, 2012 Share Posted June 27, 2012 finfo_open is only available in php version >= 5.3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.