File Upload Manager
This program displays a menu to select the file in your system, a check box, and Upload button.
Once when the user clicks the upload button, the program checks the file for existence, and undergoes series of tests as described in the plan.
Now lets look upon the code snippets…
This variable is the destination folder path.
This path is given for a Windows based system. Please change your destination folder accordingly.
Get_New_File_Name() Function
This function is called from the main program when the program encounters file exists and difference in size, date or time. This function will generate a new file name and return to the main function.
<?php
function Get_New_File_Name($file_name)
{
$sqlQuery="SELECT file_image_name
FROM file_manager
WHERE file_name LIKE '$file_name%'
AND file_parent_id=1";
$fResult=mysql_query($sqlQuery);
$Last_Version=0;
$ver=0;
if(mysql_num_rows($fResult)){
while($fRow=mysql_fetch_array($fResult)){
list($junk,$ver)=explode("_VERSION",$fRow['file_image_name']);
list($ver,$extn)=explode(".",$ver);
$Last_Version = $Last_Version > $ver ? $Last_Version : $ver;
}
}else{
$new_file_name =$file_name."_VERSION".++$Last_Version;
return $new_file_name;
}
if($Last_Version !=0){
$new_file_name=$file_name."_VERSION".++$Last_Version;
return $new_file_name;
}
}
?>