Hello,
I am having to modify a php script that was written by somebody else. There is an upload feature on the site. I need to limit the file size of the uploads by the users. there is an html form for the upload that calls a function (in a class page) for error checking. I need to add a piece of code to this function that will check file size, and if larger than 500 k, then give them an error message with a link to the faqs page.
Here is the html form for the upload:
<form id='' action='/login/upload_flyer.php' method='POST' enctype='multipart/form-data'>
<fieldset>
<legend>Upload Flyer</legend>
<p><font size=3 color=yellow>All flyers must be in PDF format, and cannot exceed 500kb size.</font><br>
<label>Flyer Name: <span class='req'>*</span><input type="text" name="flyer_name" class='' /></label>
<label>Flyer (PDF only):<input type="file" name="flyer_file" class='' /></label>
</p>
</fieldset>
<input type="hidden" name="id" class='hidden' />
<input type='submit' value='Save Flyer' class='submitButton'>
</form>
Here is the function that does the error checking:
public function checkForm($input, $required_arr=false){
foreach($this->xml->fields->field as $field_vals){
$name = trim($field_vals->input_name);
$required = $field_vals->required;
$requirement = $field_vals->requirement;
$file_types = $field_vals->allowed_file_types;
if($required=="yes"){
if (array_key_exists($name, $input)){
$error_message = $this->checkRequired($input[$name]);
if ($error_message){
$error[$name] = $error_message;
}
}
}
if(!empty($requirement) && !empty($input[$name])){
$error_message = $this->checkRequirements($input[$name], $requirement);
if ($error_message){
$error[$name] = $error_message;
}
}
if($file_types){
if (!empty($_FILES[$name]["tmp_name"])){
$ext = strtolower(ereg_replace("^.+\\.([^.]+)$", "\\1", basename($_FILES[$name]["name"])));
$pass = 0;
foreach($file_types->file_type as $ext_allowed){
if (($ext==$ext_allowed)){
$pass++;
}
}
if ($pass < 1){
$error[$name] = "Invalid File Type";
}
}
}
}
return $error;
}
What would I have to do limit the file size of the uploads?
Thanks.