Contents

 
Home
PHPRunner 6.1 manual
Prev Page Next Page
 
 

Check size and extension of uploaded files

 

To check size and extension of uploaded files use the following code in Add page: Before record added and/or Edit page: Before record updated events.

yellowbulbNote: Change the values listed in red to match your specific needs.

1. Check size and extension of uploaded files stored on a hard drive

Check file size:

$mysize=$_FILES["value_FieldName_".postvalue("id")]["size"];

if($mysize>1000000)   // if file size is greater than 1Mb

{

 $values["FieldName"]="";

 $message = "<<< File is too big >>>";

 return false;

}

Check file extension:

$exttype = CheckImageExtension($_FILES["value_FieldName_".postvalue("id")]["name"]);

if ($exttype <> ".JPG")

{

$message = "<<< Wrong file type selected >>>";

return false;

}

2. Check size and extension of uploaded files stored in a database

Check file size:

$mysize=$_FILES["value_FieldName_".postvalue("id")]["size"];

if($mysize>1000000)   // if file size is greater than 1Mb

{

$values["FieldName"]="";

$message = "<<< File is too big >>>";

return false;

}

Check file extension:

$exttype = CheckImageExtension($_FILES["value_FieldName_".postvalue("id")]["name"]);

if ($exttype <> ".JPG")

{

$message = "<<< Wrong file type selected >>>";

return false;

}

FieldName is the text field that stores filename. Before using this sample code, make sure that in Visual Editor you select this field for storing filenames. For more information, see "View as" settings - File.

view_as_file_binary

Converted from CHM to HTML with chm2web Standard 2.85 (unicode)