Home > Backend Development > PHP Tutorial > PHP file upload program (two simple file upload programs)_PHP tutorial

PHP file upload program (two simple file upload programs)_PHP tutorial

WBOY
Release: 2016-07-20 11:08:46
Original
1030 people have browsed it

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

?>


Back


endif;
?>

Method 2



File upload







File upload


if(isset($submit)){
if($myfile != "none") {
$upload_dir = "c:winnttemp";
$up=copy($myfile,$upload_dir);
if($up==1) {
print("File uploaded successfully!" );
}
else {
print ("File upload failed.");
}
unlink ($myfile);
}
else {
print ("You did not upload any files");  
}
}
?>

< /body>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444862.htmlTechArticlephp file upload program (two simple file upload programs)/*These two file upload programs are very simple , very suitable for beginners to learn PHP file upload example tutorial. php tutorial...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template