本例就一个php,适合学习,本例可以添加到数据库的代码
上传多个文件时候请一次选择多个文件,支持doc jpg pdf等
本站里面比较实用的多文件上传有很多,这边推荐一个《jQuery ajax 无刷新多图片上传并记录到数据库》
演示
PHP Code
-
- if(isset($_FILES['files'])){
- $res = upload_multiple_file($_FILES['files'],"../upload");
- echo $res;
- }
-
-
- function upload_multiple_file($file,$file_dir="../upload") {
-
- $overwrite=0;
- $allowed_file_type= array("pdf","ppt","pptx","xls","xlxs","doc","docx","jpg", "jpeg", "png", "gif");
- $max_file_size = 2097152;
-
- foreach($_FILES['files']['name'] as $fkey=> $fname){
-
- $ext = pathinfo($fname, PATHINFO_EXTENSION);
- if (!in_array($ext, $allowed_file_type)) {
-
- return "unsupported file format";
- break;
- }
-
-
- }
-
- foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
-
-
- $file_name = $_FILES['files']['name'][$key];
-
-
- $file_size =$_FILES['files']['size'][$key];
-
-
- $file_tmp_name =$_FILES['files']['tmp_name'][$key];
-
-
- $file_type=$_FILES['files']['type'][$key];
-
-
- if($file_size >0) {
- if($file_size > $max_file_size){
-
- $fsize=$max_file_size/1048576;
- return 'File size must be less than '.$fsize.' MB';
- break;
-
- }
- }
-
-
- if(is_dir($file_dir)==false){
-
- $status = mkdir("$file_dir", 0700);
-
- if($status
- return "unable to create diractory $file_dir ";
-
- }
-
- }
-
- if(is_dir($file_dir)){
-
- if($overwrite
- move_uploaded_file($file_tmp_name,"$file_dir/".$file_name);
-
- }
-
- }
-
- // $file_upload_query="INSERT into user_uploads (`u_id`,`file_name`,`file_type`) VALUES('$user_id','$file_name','$file_size','$file_type'); ";
- //mysql_query($file_upload_query);
-
-
- }
-
- return "Success";
-
- }
-
- ?>
-
原文地址:http://www.freejs.net/article_biaodan_103.html
http://www.bkjia.com/PHPjc/621645.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/621645.htmlTechArticle本例就一个php,适合学习,本例可以添加到数据库的代码 上传多个文件时候请一次选择多个文件,支持doc jpg pdf等 本站里面比较实用的多文件...
Stellungnahme:Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn