我已经制作了一个允许您将文件附加到电子邮件的表单,但是每当有人添加附件时,表单会限制他们上传大于20,000 mb的内容,但我已将max-size设置为超过50 MB,有时它甚至不会允许这么多。我的问题是如何让表单接受大小为50 MB或更多的文件?这是我用于表单的代码。
<!-- 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>
以上是代码的html部分。
下面是代码的php部分。
//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;
}
}
}
我无法弄清楚是什么限制了表单的正常工作,但我还添加了一个ini_set(&#39; memory_limit&#39;,&#39; 250M&#39;);