First, the front desk HTML form code as follows:
1 <html> 2 <head> 3 <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 4 <title>PHP中文网上传视频</title> 5 6 </head> 7 <body> 8 <form action='./upload.php' method=post enctype="multipart/form-data"> 9 <input type="hidden" name="MAX_FILE_SIZE" value="2000000000"> 10 <input type=file name=upfile size=20> 11 <input type=submit value='上传文件'> 12 </form> 13 </body> 14 </html>
Front page results are as follows:
Then upload a video background processing PHP code as follows:
. 1 ? < PHP 2 / * * . 3 * the PHP uploaded videos . 4 * / . 5 $ upfile = $ _FILES [ 'upfile' ]; . 6 . 7 function upload_file ( $ Files , $ path = "./upload", $ imagesExt = [ ' JPG ',' PNG ',' JPEG ',' GIF ',' MP4 ' ]) . 8 { . 9 // determine the error number 10 IF (@ $ files [' error '] == 00 ) { . 11 // determine the file type 12 $ EXT = strtolower (The pathinfo (@ $ Files [ 'name'], PATHINFO_EXTENSION)); 13 is IF (! the in_array ( $ EXT , $ imagesExt )) { 14 return "illegal file type" ; 15 } 16 . 17 // determines whether upload directory exists 18 is IF (! is_dir ( $ path {)) . 19 mkdir ( $ path , 0777, to true ); 20 is } 21 is 22 is // generate unique file name 23 is $ fileName = MD5( Of uniqid ( microtime, and ( to true ), to true )). '.'. $ EXT ; 24 25 // splicing file name to the specified directory 26 is $ destName = $ path "/.". $ FileName ; 27 28 // mobile files 29 IF (! move_uploaded_file ( $ files [ 'tmp_name'], $ destName )) { 30 return "failed files!" ; 31 is } 32 return "file uploaded successfully!" ; 33 }the else { 34 is // the error message returned number 35 Switch (@ $ Files [ 'error' ]) { 36 Case . 1: 37 [ echo "uploaded file exceeds the limit value of the php.ini upload_max_filesize option" ; 38 is BREAK ; 39 Case 2: 40 echo "upload file size exceeds the value specified by the option MAX_FILE_SIZE HTML form" ; 41 is BREAK ; 42 is Case . 3: 43 is echo "file was only partially uploaded" ; 44 is BREAK ; 45 Case . 4: 46 is echo"No file was uploaded" ; 47 BREAK ; 48 Case . 6: 49 Case . 7: 50 echo "system error" ; 51 is BREAK ; 52 is } 53 is } 54 is 55 } 56 is 57 is echo upload_file ( $ upfile ); 58 59 >?
Well, in this PHP code, we define a upload_file upload function, the function can be achieved not only by this but also to achieve video upload picture upload.
And we have detailed notes to tell you the meaning of each operation, easy reference study.
Finally, we can choose to upload a video test results are as follows:
Link: https: //mp.weixin.qq.com/s/Go5tzd1_omhgNyn6d3BKzA