Jump to content

ianhaney

Members
  • Content Count

    330
  • Joined

  • Last visited

Community Reputation

0 Neutral

About ianhaney

  • Rank
    Advanced Member

Profile Information

  • Gender
    Not Telling
  1. Manged to get the array printed out and the results are below Array ( [name] => Array ( [0] => ) [type] => Array ( [0] => ) [tmp_name] => Array ( [0] => ) [error] => Array ( [0] => 4 ) [size] => Array ( [0] => 0 ) ) Looking at the error codes online, it looks like 4 means no file was uploaded but I need the upload file be optional so the form can be submitted without files uploaded as we
  2. I put the code in like below but does not say what's in the userfile, just says the same notice about only the jpg etc files allowed $allowed = array( 'jpg', 'jpeg', 'gif', 'png'); if (is_array($_FILES['userfile'])) { foreach($_FILES['userfile']['name'] as $name) { $type = pathinfo($name, PATHINFO_EXTENSION); if(!in_array($type, $allowed)) die("Error: Only jpg, jpeg, gif and png files are allowed.-".$type); } } } echo "<pre>"; print_r($_FILES['userfile']); echo "</pre>"; Have I put the print code in the wrong plac
  3. Getting closer, I have updated the code to below and it now gives me the notice if trying to upload a file that is not allowed so go back to the form and upload the correct file types and it send the email and redirects me to the confirmation page but if try to send the form with no files attached, I get the notice Error: Only jpg, jpeg, gif and png files are allowed. $msg = ''; if (array_key_exists('userfile', $_FILES)) { // create object of PHPMailer class with boolean parameter which sets/unsets exception. $mail = new PHPMailer(true); //$mail->isSMTP(); // using SMTP protoc
  4. Tried it again and still getting a blank white page but no error log this time on the server so guessing the code is almost correct and it's sending the email if there is attachments but if no attachments it shows the error message Error: Only jpg, jpeg, gif and png files are allowed.- and it's not redirecting to the confirmation page when there are files attached and guessing will do the same when no files are attached
  5. Just checked again and it was on PHP 7.3 (alt-php73) so changed it to PHP 7.3 (ea-php73) and will see if that makes a difference
  6. It's odd one as never had the error come up before until today, I'm running php version 7.3.6
  7. The whole code is below as thought that might be better to post the whole code and to follow $msg = ''; if (array_key_exists('userfile', $_FILES)) { // create object of PHPMailer class with boolean parameter which sets/unsets exception. $mail = new PHPMailer(true); try { //$mail->isSMTP(); // using SMTP protocol $mail->Host = 'host'; // SMTP host as gmail $mail->SMTPAuth = true; // enable smtp authentication $mail->Username = 'emailaddress'; // sender gmail host $mail->Password = 'emailpassword'; // sender gmail host password
  8. I updated the code to the following $allowed = array( 'jpg', 'jpeg', 'gif', 'png'); if (is_array($_FILES['userfile'])) { foreach($_FILES['userfile']['name'] as $name) { $type = pathinfo($name, PATHINFO_EXTENSION); if(!in_array($type, $allowed)) die("Error: Only jpg, jpeg, gif and png files are allowed.-".$type); } } and below //Attach multiple files one by one for ($ct = 0, $ctMax = count($_FILES['userfile']['tmp_name']); $ct < $ctMax; $ct++) { $uploadfile=$name.'.'.pathinfo($name, PATHINFO_EXTENSION);
  9. Been playing about with the code and getting there I think, it now works and shows the message if I try to send the form with a incorrect file type, it gives me the notice that it's the wrong file type and have to go back to the form to upload the correct file type and the code sends the form with the correct file type so that bit is all ok and working but tested with no file attachment and it's saying the message as if I was selecting a non allowed file type, below is the updated code $allowed = array( 'jpg', 'jpeg', 'gif', 'png'); foreach($_FILES['userfile']['name'] as $name) {
  10. They don't show any messages no but guess that's because they don't need to as they are not failing to trigger the msg line
  11. Sorry forgot about that line, the line $msg = ''; if (array_key_exists('userfile', $_FILES)) { is just above $mail = new PHPMailer(true); I don't get any errors show
  12. I have currently updated the code to the following but does not say the message about only uploading jpg or png files, the email does work though if I do upload the wrong file and I receive the email but don't attach the wrong file type attachment but if I attach the correct file types, it sends the email with the attachments //Attach multiple files one by one for ($ct = 0, $ctMax = count($_FILES['userfile']['tmp_name']); $ct < $ctMax; $ct++) { $uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])); $filename = $_FILES['user
  13. I found a example below but unsure how to know that only jpg or png files can be uploaded/attached $fname = $_FILES['file']['name']; $this->ext = pathinfo($fname, PATHINFO_EXTENSION); //I assume you've done the if move_upload thing to get the file to its destination $this->filename = $name.'-'.date('dmY-Hi').'-cv.'.$this->ext; $mail->AddAttachment('files/cvs/'.$this->filename, "CV File");
  14. I did try the following //Attach multiple files one by one for ($ct = 0, $ctMax = count($_FILES['userfile']['tmp_name']); $ct < $ctMax; $ct++) { $uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])); $filename = $_FILES['userfile']['name'][$ct]; $AllowedFileTypes = array("jpg","png"); // build array $FileName = $_FILES['userfile']['name']; // get filename of file input $FileType = end((explode(".", $FileName))); // get file type/extension if(in_array($FileType, $AllowedFileTypes)){ //
  15. Thank you but unsure how to do that in phpmailer
×
×
  • 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.