PHP implements a complete example of video file upload,
This document provides a complete example to upload video files. Although it is a relatively basic application, it still has some reference value. Share it with you for your reference. The specific method is as follows:
First, for PHP, video is also a file. We can use this principle to upload PHP video files in a similar way as uploading common files. The difference is that the video file is generally large and the upload time is long, and the php configuration file also has a limit on the size of the file to be uploaded.
If you need to use PHP to upload files, we recommend that you use FTP to upload files.
I. PHP processing code:
<? Php // you can set up to 10 files to upload define ('muilti _ file_upload', '10') at the same time; // you can set the file size to not exceed 5 MBdefine ('max _ SIZE_FILE_UPLOAD ', '000000'); // set the storage directory of the uploaded FILE ('file _ UPLOAD_DIR ','/fileuploads '); // file extension $ array_extention_interdite = array ('. flv ','. wmv ','. rmvb ','. php ','. php3 ','. php4 ', '.exe ','. msi ','. htaccess', '.gz '); // public function func_message ($ message = '', $ OK ='') {echo' <table width = "100%" cellspaci Ng = "0" cellpadding = "0" border = "0"> '; if ($ OK = true) echo '& lt; tr & gt; <td width = "50%" & gt '. $ message. '</td> </tr>'; else echo '<tr> <td width = "50%"> '. $ message. '</td> </tr>'; echo '</table> ';} // process form submission $ action = (isset ($ _ POST ['action'])? $ _ POST ['action']: ''; $ file = (isset ($ _ POST ['file'])? $ _ POST ['file']: ''; if ($ file! = '') $ File = $ file. '/'; $ message_true = ''; $ message_false =''; switch ($ action) {case 'upload': chmod (FILE_UPLOAD_DIR, 0777 ); for ($ nb = 1; $ nb <= MUILTI_FILE_UPLOAD; $ nb ++) {if ($ _ FILES ['file _'. $ nb] ['SIZE']> = 10) {if ($ _ FILES ['file _'. $ nb] ['SIZE'] <= MAX_SIZE_FILE_UPLOAD) {if (! In_array (ereg_replace ('^ [[: alnum:] ([-_.]? [[: Alnum:]) *. ','. ', $ _ FILES ['file _'. $ nb] ['name']), $ array_extention_interdite) {if ($ _ POST ['file _ name _'. $ nb]! = '') $ File_name_final = $ _ POST ['file _ name _'. $ nb]. $ extension; else $ file_name_final = $ _ FILES ['file _'. $ nb] ['name']; // modify the file name $ file_name_final = strtr ($ file_name_final, 'aaaaa', 'weight '); $ file_name_final = preg_replace ('/([^. a-z0-1] +)/I ',' _ ', $ file_name_final); $ _ FILES ['file _'. $ nb] ['name'] = $ file_name_final; // start to upload move_uploaded_file ($ _ FILES ['file _'. $ Nb] ['tmp _ name'], FILE_UPLOAD_DIR. $ file. $ file_name_final); $ message_true. = 'file uploaded successfully :'. $ _ FILES ['file _'. $ nb] ['name']. '<br>';} else $ message_false. = 'file Upload Failed :'. $ _ FILES ['file _'. $ nb] ['name']. '<br>';} else $ message_false. = 'maximum file size cannot exceed '. MAX_SIZE_FILE_UPLOAD/1000. 'kb :"'. $ _ FILES ['file _'. $ nb] ['tmp _ name']. '"<br>'; }}// end for break;}?>
II. the HTML code is as follows:
<Html>