The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Need some help with file uploading via form and checking file validation

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #31579

    I need some help with the following:

    I have a simple from where someone can upload a CV for a job. (in word or pdf)
    I want to check the file type and the file size before sending it via an html email to the recepient.

    All is working well except for checking the file size?

    If i upload a bigger file (.pdf or .doc) then allowed i get this error?

    Notice: Undefined index: filea in C:wampwwwLMCGroeptest-uploadfile.php on line 10
    The file you attempted to upload is not allowed.

    So its not getting checked for filesize???
    I can’t get it to work as I would like ….so can anyone help me out here?

    I have a simple form like this:

    I have a php file with this:

    // Configuration - Your Options
    $allowed_filetypes = array('.pdf','.doc'); // usage ('.jpg','.gif','.pdf') These will be the types of file that will pass the validation.
    $max_filesize = 2048500; // Maximum filesize in BYTES (currently 2MB).
    $maxfileMB = round($max_filesize/1048576, 2);
    $upload_path = 'temp/'; // The place the files will be uploaded to (currently a 'files' directory).
    $SendEmailTo = "[email protected]"; // emailadres to send file to

    $filename = $_FILES; // Get the name of the file (including file extension).
    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

    // Check if the filetype is allowed, if not DIE and inform the user.
    die('The file you attempted to upload is not allowed.');

    // Now check the filesize, if it is too large then DIE and inform the user.
    if(filesize($_FILES) > $max_filesize)
    die('The file you attempted to upload is too large.');

    // request variables
    $from = $_REQUEST;
    $emaila = $_REQUEST;

    if ($from && $emaila) {
    function mail_attachment ($from , $to, $subject, $message, $attachment){
    $fileatt = $attachment; // Path to the file
    // $fileatttype = "application/octet-stream"; // Filetype
    $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
    $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment

    $email_from = $from; // Who the email is from
    $subject = "Nieuwe vacature bijlage";
    $email_subject = $subject; // The Subject of the email
    //$email_txt = $message; // Message that the email has in it
    $email_to = $to; // Who the email is to

    $file = fopen($fileatt,'rb');
    $data = fread($file,filesize($fileatt));
    $msg_txt="nn U heeft een nieuwe vacature bijlage ontvangen van $from";
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers = "From: ".$email_from;
    $headers .= "nMIME-Version: 1.0n" . "Content-Type: multipart/mixed;n" . " boundary="{$mime_boundary}"";
    // $headers .= 'Bcc: [email protected]' . "rn";
    $email_txt = $msg_txt;
    $email_message = "This is a multi-part message in MIME format.nn" .
    "--{$mime_boundary}n" .
    "Content-Type:text/html; charset="iso-8859-1"n" .
    "Content-Transfer-Encoding: 7bitnn" . $email_txt . "nn";
    $data = chunk_split(base64_encode($data));
    $email_message .= "--{$mime_boundary}n" .
    "Content-Type: {$fileatt_type};n" .
    " name="{$fileatt_name}"n" .
    "Content-Disposition: attachment;n" .
    "filename="{$fileatt_name}"n" .
    "Content-Transfer-Encoding: base64nn" .
    $data . "nn" .

    $ok = mail($email_to, $email_subject, $email_message, $headers);
    if($ok) {
    //redirect to the 'thank you' page
    header('Location: bedankt.php');
    // echo "File Sent Successfully.";
    unlink($attachment); // delete a file after attachment sent.
    } else {
    die("Sorry but the email could not be sent. Please go back and try again!");
    mail_attachment("$from", $SendEmailTo , "subject", "message", ($upload_path.$_FILES["filea"]["name"]));



    Am I right in thinking your 2Mb limit is set in your ini file? Might be worth setting the $max_filesize by using ini_get(‘upload_max_filesize’); ?


    Hi TT_Mark,

    Yes you are right the limit is set to 2MB in my ini file.
    Changing this to a lower value, in the declarations or in my ini flie does not change the error that is displayed!!



Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.