This article mainly introduces the use of PHP to accept files and get the prefix name of the method, the author highlighted the use of $_files global variables, the need for friends can refer to the following
Form form for HTML
The HTML form simulates a POST request for a file upload, with the following code:
<! DOCTYPE html>
Attention:
To ensure that the file upload form's properties are Enctype= "Multipart/form-data", the file cannot be uploaded
Php
First, you need to explain the PHP global variable $_files, which contains all the uploaded file information
$_file[' UserFile ' [' Name ']: The original name of the client machine file
$_file[' userfile ' [' type ']: MIME type of File
$_file[' userfile ' [' size ']: Uploaded file size
$_file[' UserFile ' [' Tmpname ']: temporary file names stored on the server after files are uploaded
$_file[' userfile ' [' Error ']: and the file upload error code
Ideas
1. Generate 40-bit random string as file name
2, depending on whether the file is a picture or voice transferred to a different file location
3, temporarily do not do file size and file type verification
function Processfile ($files, $type) { $uploadName = null; foreach ($files as $name = + $value) { $originalName = $value [' name ']; $arr = Explode (".", $originalName); $postfix = $arr [Count ($arr)-1]; $tmpPath = $value [' Tmp_name ']; $tmpType = $value [' type ']; $tmpSize = $value [' size ']; } $newname = Ehlstaticfunction::generaterandomstr (40). ".". $postfix; Switch ($type) {case 1: //processing sound file $destination = Videouploaddir. $newname; break; Case 2: //Processing image file $destination = Imageuploaddir. $newname; break; } Move_uploaded_file ($tmpPath, $destination); }
You can use the code to get the suffix of the uploaded file:
Html
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Php
<? PHP if (isset ($_post[' submit ')) { $string = Strrev ($_files[' upfile ' [' name ']); $array = Explode ('. ', $string); echo $array [0]; } ? >
Examples of results:
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
PHP uses Preg_split and explode to implement the method of partitioning textarea storage content
PHP implementation of file lock locking, unlocking method
PHP implementation method based on cookie to set the user to not operate the auto Exit function for 30 minutes