Home > php教程 > php手册 > body text

php 文件上传程序(二款简单文件上传程序)

WBOY
Release: 2016-06-13 11:24:39
Original
997 people have browsed it

php 文件上传程序(二款简单文件上传程序)/*这二款文件上传程序是非常简单的,很适合初学者的学习php时的文件上传实例教程哦。

php教程 文件上传程序(二款简单文件上传程序)
/*
这二款文件上传程序是非常简单的,很适合初学者的学习php时的文件上传实例教程哦。
*/

if(!$uploadaction):
?>



文件上载界面


















else:
?>



文件上载代码


$uploadaction=0;
echo "good!";
$timelimit=60; /*设置超时限制时间 缺省时间为30秒 设置为0时为不限时 */
set_time_limit($timelimit);

if(($uploadfile !="none" ))
{  
    $uploadpath=addslashes(dirname($path_translated))."upload"; //上载文件存放路径

    $filename=$uploadpath.$uploadfile_name; //上载文件名

    if($uploadfile_size     {
  $filesize=(string)$uploadfile_size." 字节"; 
 }
     elseif ($uploadfile_size      {
  $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 "文件 $uploadfile_name ($filesize)上载成功!"; }
         else
         { echo "文件 $uploadfile_name上载失败!"; }

         unlink($uploadfile);
    }
    else
    { echo "文件 $uploadfile_name已经存在!"; }
}
else
{ echo "你没有选择任何文件上载!"; }

set_time_limit(30); //恢复缺省超时设置

?>


返回



endif;
?>

方法二



文件上传






文件上传


if(isset($submit)){
 if($myfile != "none") {
  $upload_dir = "c:winnttemp";
  $up=copy($myfile,$upload_dir);
  if($up==1) {
   print("文件上传成功!");
  }
  else {
   print ("文件上传失败.");
  }
  unlink ($myfile);
 }
 else {
  print("你没有上传任何文件");   
 }
}
?>



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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!