分享

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

 krrish 2010-08-25

/*
 在学习php中 文件上传是一门重要的核心技术,今天《php 文件上传程序(二款简单文件上传程序)》介绍了二款文件上传程序,这两款文件上传程序是非常简单的,很适合初学者的学习php时的文件上传实例教程哦。
*/

if(!$uploadaction):
?>

<html>
<head>
<title>文件上载界面 php 文件上传程序</title>
</head>
<body>

<table>
<tr align="center">
<td><form enctype="multipart/form-data" name="submitform" action="upload.php" method="post">
<input type="hidden" name="max_file_size" value="1000000"><input type="hidden" name="uploadaction" value="1">
</td></tr>
<tr align="center">
<td><input name="uploadfile" type="file" size="30"></td>
</tr>
<tr align="center">
<td><input name="submit" value="提交" type="submit"></td>
<td><input name="reset" value="重置" type="reset"></td>
</tr>
</form>
</table>
</center>
</body>
</html>

<?
else:
?>

<html>
<head>
<title>文件上载代码  php 文件上传程序</title>
</head>
<body>

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

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

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

?>

<br><a href = "upload.php">返回</a>

</body>
</html>

<?
endif;
?>

方法二

<html>
<head>
<title>文件上传 php 文件上传程序</title>
</head>
<body>
<table>
<form enctype="multipart/form-data" name=myform method="post">
<tr><td>文件上传</td><td><input name="myfile" type="file"></td></tr>
<tr><td colspan="2"><input name="submit" value="上传" type="submit">
</form>
<?php
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("你没有上传任何文件");   
 }
}
?>
</td></tr>
</table>
</body>
</html>

php 文件上传程序

本文来源网页制作教程网www. 原文链接:http://www./php100/php-1040.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多