二款php文件上传程序
这二款文件上传程序应该是php中文件上传功能最简单的吧,基本没做任何判断,直接把文件上传到了服务器.
第一款文件上传代码:
$sort =12; $f_type = strtolower ( "swf,jpg,rar,zip,7z,iso,gif" ); //设置可上传的文件类型 $file_size_max =200*1024*1024; //限制单个文件上传最大容量//开源代码phpfensi.com $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>" ; ?>第二款文件上传代码:
$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( echo $result ; ?>, ' ' );</script>查看更多关于二款php文件上传程序 - php上传下载的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did29326