二款php文件上传程序

$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
$file_size_max=200*1024*1024;//限制单个文件上传最大容量
$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
$f_input="files";//设置上传域名称
    foreach($_files[$f_input]["error"] as $key => $error){
        $up_error="no";
        if ($error == upload_err_ok){
            $f_name=$_files[$f_input]['name'][$key];//获取上传源文件名
   
            $uploadfile=$uploaddir.strtolower(basename($f_name));
            
            $tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
   $tmp_type=strtolower($tmp_type);
            if(!stristr($f_type,$tmp_type)){
                echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
                $up_error="yes";
            }
            
            if ($_files[$f_input]['size'][$key]>$file_size_max) {
   
                echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_files[$f_input]
['size'][$key]/1024)."kb,大于规定的".($file_size_max/1024)."kb,上传失败!')</script>";
                $up_error="yes";
            }
            
            if (file_exists($uploadfile)&&!$overwrite){
                echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
                $up_error="yes";
            }
             $string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
  $rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdhis").substr($gettime[0],2,6).$rand;
$attdir="./file/"; 
    if(!is_dir($attdir))  
    {  mkdir($attdir);}
            $uploadfile=$attdir.$t.".".$tmp_type;
            if(($up_error!="yes") and (move_uploaded_file($_files[$f_input]['tmp_name']

[$key], $uploadfile))){

                
    $_msg=$_msg.$f_name.'上传成功 ';
    
    
            }
   else{
   $_msg=$_msg.$f_name.'上传失败 ';
   }
        }
 
    }
echo "<script>window.parent.finish('".$_msg."');</script>"; 
?>

第二款文件上传代码

<?php
   $destination_path = '../../upfile/jianjulogo/';//getcwd().directory_separator;

   $result = 0;
  
   $target_path = $destination_path . basename( $_files['myfile']['name']);

   if(@move_uploaded_file($_files['myfile']['tmp_name'], $target_path)) {
      $result = 1;
   }
   echo $target_path;
 sleep(1);

?>
<script language="网页特效" type="text/javascript">window.top.window.stopupload(<?php echo $result; ?>,'<?=$target_path?>');</script>

时间: 2024-08-01 16:48:24

二款php文件上传程序的相关文章

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

 代码如下 复制代码 if(!$uploadaction): ?> <html> <head> <title>文件上载界面</title> </head> <body> <table> <tr align="center"> <td><form enctype="multipart/form-data" name="submitform&

超简单的php文件上传程序

 代码如下 复制代码 <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=&qu

ASP.NET文件上传程序的源代码

asp.net|程序|上传|源代码 本文件用VB.NET编辑,在WIN2000+IIS(安装有.NET支持)中调试通过,可以上传许多常用的文件类型.如RAR.ZIP.DOC.TXT.JPG.GIF等等!直接下载保存为ASPX格式就可以------------------------------------------------------------<html><title>文件上传</title> <body><form enctype="

php中实现图片文件上传程序代码

我们先来看一下项目结构图与数据库结构图吧 项目结构: 运行效果:   up.html 简单的上传表单文件  代码如下 复制代码 <form action="up.php" enctype="multipart/form-data" method="post"      name="uploadfile">上传文件:<input type="file" name="upfile&q

php文件上传程序(支持缩略图)(1/2)

 代码如下 复制代码 <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=&qu

php 实现多文件上传程序代码

最简单的实例如下  代码如下 复制代码 <form action="" method="post" enctype="multipart/form-data"> <p>Pictures: <input type="file" name="pictures[]" /> <input type="file" name="pictures[]

文件上传程序的全部源码

1.upfile.php文件 <html> <body> <title>文件上传</title> <form enctype="multipart/form-data" action=upload.php method=post> <input type=file name=upfile size=10><br><br> <input type=submit value='上载文件'&

5款Ajax 文件上传控件_AJAX相关

1. FancyUpload (演示地址) FancyUpload是一个采用Flash与Ajax(MooTools)技术实现包含上传进度条的多文件上传组件,类似于SWFUpload. 2. SwfUploadPanel (演示地址) SwfUploadPanel是一个结合SwfUpload v2.0.2与ExtJS 2.0.x开发的多文件上传面板(panel). 3. Yahoo! UI Library: Uploader (演示地址) YUI Uploader Control结合Flash开发

实现ASP.NET多文件上传程序代码_实用技巧

upload.aspx 复制代码 代码如下: <%@ Page language="c#" Codebehind="UpLoad.aspx.cs" AutoEventWireup="false" Inherits="WebPortal.Upload" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >