This example is just PHP, suitable for learning. This example can be added to the code of the database
When uploading multiple files, please select multiple files at once, support doc, jpg, pdf, etc.
This There are many practical multi-file uploads on the site. Here we recommend a "jQuery ajax multi-image upload without refreshing and recording to the database"
Demo
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";
-
- }
-
- ?>
-
Original address: http://www.freejs. net/article_biaodan_103.html
http://www.bkjia.com/PHPjc/621645.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621645.htmlTechArticleThis example is just PHP, suitable for learning. This example can be added to the database code. Please upload multiple files once. Select multiple files, support doc jpg pdf and other more practical multiple files on this site...