0

I've made a form that will let you attach a file to the email, however whenever someone adds an attachment, the form restricts them from uploading anything larger than 20,000 mb but I have set the max-size to well over 50 mb, sometimes it won't even allow that much. My question is how can I get the form to accept files as large as 50 mb or more? here is the code that I used for my form.

<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>

<fieldset >
<legend>Upload A File</legend>

<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text2'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />

<div class='short_explanation'>* required fields</div>

 <div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container2'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text2' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
 </div>
<div class='container2'>
<label for='email' >Email Address*:</label><br/>
<input type='text2' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container2'>
<label for='phone' >Phone Number*:</label><br/>
<input type='text2' name='phone' id='phone' value='<?php echo $formproc->SafeDisplay('phone') ?>' maxlength="15" /><br/>
<span id='contactus_phone_errorloc' class='error'></span>
</div>
<div class='container2'>
<label for='company' >Company Name: </label><br/>
<input type='text2' name='company' id='company' value='<?php echo $formproc->SafeDisplay('company') ?>' maxlength="50" /><br/>
<span id='contactus_company_errorloc' class='error'></span>
</div>
<div class='container2'>
<label for='Product_type' >Regarding:</label><br/>
<select name='Product_type'>
    <option>Business Cards</option>
    <option>Brochures</option>
    <option>Flyers</option>
    <option>Signage</option>
    <option>Banners</option>
    <option>Business Stationary</option>
    <option>Personal Stationary</option>
    <option>Posters</option>
    <option>Tickets</option>
    <option>Invitations</option>
    <option>Funeral Programs</option>
    <option>Announcements</option>
    <option>Program Booklets</option>
    <option>Magnets</option>
    <option>Postcards</option>
    <option>Name Tags</option>
    <option>Mailers</option>
    <option>Sell Sheets</option>
    <option>Pocket Folders</option>
    <option>Door Hangers</option>
    <option>Coupons</option>
    <option>Conference Book</option>
    <option>Calendars</option>
    <option>Labels</option>
    <option>Stickers</option>
    <option>Menus</option>
    <option>Decals</option>
</select>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container2'>
<label for='paper_type' >Paper Type:</label><br/>
<select name='paper_type'>
    <option>Cover</option>
    <option>Text Weight</option>
</select>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container2'>
<label for='finish_type' >Finish:</label><br/>
<select name='finish_type'>
    <option>Uncoated</option>
    <option>Matte</option>
    <option>Gloss</option>
</select>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container2'>
<label for='quantity' >Quantity: </label><br/>
<input type='text2' name='quantity' id='quantity' value='<?php echo $formproc->SafeDisplay('quantity') ?>' maxlength="50" /><br/>
<span id='contactus_quantity_errorloc' class='error'></span>
</div>
<div class='container2'>
<label for='photo' >Your File:</label><br/>
<input type="file" name='photo' id='photo' /><br/>
<span id='contactus_photo_errorloc' class='error'></span>
</div>
<div class='container2'>
<label for='message' >Message:</label><br/>
<span id='contactus_message_errorloc' class='error'></span>
<textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<!--<div class='container2'>
<label for='photo2' >Your File:</label><br/>
<input type="file" name='photo2' id='photo2' /><br/>
<span id='contactus_photo_errorloc' class='error'></span>
</div>-->
<div class='container2'>
<div><img alt='Captcha image' src='show-captcha.php?rand=1' id='scaptcha_img' /></div>
<label for='scaptcha' >Enter the code above here:</label>
<input type='text2' name='scaptcha' id='scaptcha' maxlength="10" /><br/>
<span id='contactus_scaptcha_errorloc' class='error'></span>
<div class='short_explanation'>Can't read the image?
<a href='javascript: refresh_captcha_img();'>Click here to refresh</a>.</div>
</div>


<div class='container2'>
<input type='submit' name='Submit' value='Submit' />
</div>

</fieldset>
</form>

Above is the html part of the code.

Below is the php part of the code.

        //file upload validations
    if(!empty($this->fileupload_fields))
    {
     if(!$this->ValidateFileUploads())
     {
        $ret = false;
     }
    }
    return $ret;
}

function ValidateFileType($field_name,$valid_filetypes)
{
    $ret=true;
    $info = pathinfo($_FILES[$field_name]['name']);
    $extn = $info['extension'];
    $extn = strtolower($extn);

    $arr_valid_filetypes= explode(',',$valid_filetypes);
    if(!in_array($extn,$arr_valid_filetypes))
    {
        $this->add_error("Valid file types are: $valid_filetypes");
        $ret=false;
    }
    return $ret;
}

function ValidateFileSize($field_name,$max_size)
{
    $size_of_uploaded_file =
            $_FILES[$field_name]["size"]/80000;//size in KBs
    if($size_of_uploaded_file > $max_size)
    {
        $this->add_error("The file is too big. File size should be less than $max_size KB");
        return false;
    }
    return true;
}

function IsFileUploaded($field_name)
{
    if(empty($_FILES[$field_name]['name']))
    {
        return false;
    }
    if(!is_uploaded_file($_FILES[$field_name]['tmp_name']))
    {
        return false;
    }
    return true;
}
function ValidateFileUploads()
{
    $ret=true;
    foreach($this->fileupload_fields as $upld_field)
    {
        $field_name = $upld_field["name"];

        $valid_filetypes = $upld_field["file_types"];

        if(!$this->IsFileUploaded($field_name))
        {
            continue;
        }

        if($_FILES[$field_name]["error"] != 0)
        {
            $this->add_error("Error in file upload; Error code:".$_FILES[$field_name]["error"]);
            $ret=false;
        }

        if(!empty($valid_filetypes) &&
         !$this->ValidateFileType($field_name,$valid_filetypes))
        {
            $ret=false;
        }

        if(!empty($upld_field["maxsize"]) &&
        $upld_field["maxsize"]>0)
        {
            if(!$this->ValidateFileSize($field_name,$upld_field["maxsize"]))
            {
                $ret=false;
            }
        }

    }

I can't figure out what is restricting the form from working properly but I also added a ini_set('memory_limit', '250M');

[I've also attached a link to the page so you can see for yourself what the form is doing.

  • *20,000 mb* ... 20 Gig? O_o – CD001 May 19 '17 at 15:18
  • in your function "function ValidateFileSiz" you're only allowing an 80kb upload limit? – Alex May 19 '17 at 15:25
  • yes, is that not the equivalent to 80mb? –  May 19 '17 at 16:32
  • you'll need to change your max post size in php.ini, as well as max file upload size. As stated there is no need to divide by 80000 in your "ValidateFileSize", if anything divide by 1024. or don't divide at all. – ATechGuy May 19 '17 at 16:33
  • @user7436497 you have written 20,000 MB, in English that means 20 GB, you probably meant to write 20 MB, not 20,000MB. That's what he is saying – ATechGuy May 19 '17 at 16:35
  • so could you provide me with a written example of what that might look like? @ATechGuy –  May 19 '17 at 16:36
  • if you are referring to the php.ini, look at this question and answer http://stackoverflow.com/questions/2184513/php-change-the-maximum-upload-file-size . Check your php.ini first to make sure the system will allow it, then move on from there. – ATechGuy May 19 '17 at 16:38
  • ok so if they cannot allow it then am I able to change it? @ATechGuy also, if I'm using hosting service how could I check that? –  May 19 '17 at 16:39

0 Answers0