STEP 2
Next step is to define the strings for the file extension allowed to be uploaded. Only this extension will be able to move on your server.
For this part you must to create a php page named upload.php in which you have to copy the following lines at the beginning of code .
This part of code validate file extensions to be uploaded via form
//=======================
$extensions = array('.png', '.gif', '.jpg', '.jpeg','.PNG', '.GIF', '.JPG', '.JPEG');
$valid_extensions = '.png , .gif, .jpg, .jpeg';
$extension = strrchr($_FILES['userfile']['name'], '.');
//=======================
You can change alowed extension with your own.
Next step: copy this code below :
//================
if (!in_array($extension, $extensions))
{
echo'<center>wrong files format , alowed only <strong>"'.$valid_extensions.'"</strong></center>';
}
//=========================
Note!
$extensions = array('.png', '.gif', '.jpg', '.jpeg','.PNG', '.GIF', '.JPG', '.JPEG');
we write lower and UPPER leters because some servers do not make the difference ( sensitive case )
The error message for extension validation will be :
wrong files format , alowed only ".png , .gif, .jpg, .jpeg"
!! You can change the text for this error message but not the part "'.$valid_extensions.'" ';
» CREATE HTML ( PHP ) FORM
» STEP 2 : VALIDATION PHP : CHECK FILE EXTENSION IF IS ALOWED / NOT ALLOWED TO BE UPLOADED
» STEP 3 : VALIDATION PHP : CHECK IF A FILE WITH THE SAME NAME EXIST ON SERVER
» STEP 4 : VALIDATION PHP : CHECK THE FILE MAXIMUM SIZE
» STEP 5 : MOVE UPLOAD FILE IN UPLOAD DIRECTORY ON SERVER
» STEP 6: DEMO PAGE -PHP UPLOAD SCRIPT IN ACTION
» STEP 7: DOWNLOAD THE SCRIPT