Home > Article > Backend Development > PHP file upload program (two simple file upload programs)_PHP tutorial
PHP file upload program (two simple file upload programs)/*These two file upload programs are very simple and are very suitable for beginners to use file upload example tutorials when learning PHP.
php tutorial file upload program (two simple file upload programs)
/*
These two file upload programs are very simple and are very suitable for beginners to learn php file upload example tutorials.
*/
if(!$uploadaction):
?>
< ;/center>
else:
?>
File upload code
$ uploadaction=0;
echo "good!";
$timelimit=60; /*Set the timeout limit, the default time is 30 seconds and set to 0, it is unlimited*/
set_time_limit($timelimit) ;if(($uploadfile !="none" ))
{
$uploadpath=addslashes(dirname($path_translated))."upload"; //Upload file storage path$filename=$uploadpath.$uploadfile_name; //Upload file name
if($uploadfile_size < 1024) //Upload file size
{
$filesize=(string) $uploadfile_size." bytes";
}
elseif ($uploadfile_size <(1024 * 1024))
{
$filesize=number_format((double)($uploadfile_size/1024), 1 ) . " kb";
}
else{
$filesize=number_format((double)($uploadfile_size / (1024 * 1024)), 1) . " mb";
}
if(!file_exists($filename))
{
if(copy($uploadfile,$filename))
{ echo "File $uploadfile_name ($filesize) uploaded successfully! "; }
else
{ echo "File $uploadfile_name failed to upload! "; }unlink($uploadfile);
}
else
{ echo "The file $uploadfile_name already exists! "; }
}
else
{ echo "You did not select any files to upload! "; }set_time_limit(30); //Restore the default timeout setting
?>
endif;
?>Method 2
File upload
< /body>