二款php文件上传程序
这二款文件上传程序应该是php中文件上传功能最简单的吧,基本没做任何判断,直接把文件上传到了服务器.
第一款文件上传代码:
- $sort=12;
- $f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");
- $file_size_max=200*1024*1024;
- $overwrite = 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>";
- ?>
第二款文件上传代码:
- $destination_path = '../../upfile/jianjulogo/';
-
- $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(echo $result; ?>,'=$target_path?>');</script>