STEP 3
CHECK THE DUPLICAT NAME OF FILES ON YOUR SERVER
If we don't do this validation on upload script we will have a unpleasant situation . A file with the same name will be rewritten into the upload folder with the new one. To avoid such situations we have to do the following validation:
First we have to replace the empty space from name of files in upload.php
//==================
$file_name = $_FILES['userfile']['name'];
$file_name = str_replace(' ', '_', $file_name);
//==================
Then we will check the existence of a file with the same name:
//==================
if (file_exists('upload/' .$file_name))
{
echo'The file <strong>"'.$_FILES['userfile']['name'].'"</strong>already exist to our server<br>You have to rename the file in your pc!';
}
//===================
Also we can adding to the name of file a character or something to differentiate it from the existing duplicate file .
//===============
if (file_exists('upload/' .$file_name))
{
$file_name = $file_name.'something_here';
}
//===============
NOTE:
Replacing empty spaces with " _ " . can be necessary when you linking to a uploaded file. The empty spaces can generate big problems ...
you can use also "-"
» 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 7: DOWNLOAD THE SCRIPT