For the sake of simplicity, PHP files are written in a file with the form form.
PHP Single File upload---->
1 2 3 4
5 6 7 A - - the - -
Php -if(!Empty($_files)){ +Header(' Content-type:text/html;charset=utf-8 '); -$fileInfo=$_files[' MyFile ']; +Print_r($_files); A//Exit and print the error message if an upload error occurs atif($fileInfo[' Error ']>0){ -Switch($fileInfo[' Error ']){ - Case1: -$msg _error= ' The upload file exceeds the value of the upload_max_filesize option in the PHP configuration file '; - Break; - Case2: in$msg _error= ' exceeds the size of the form max_file_size limit '; - Break; to Case3: +$msg _error= ' File partial upload '; - Break; the Case4: *$msg _error= ' No file Upload '; $ Break;Panax Notoginseng Case6: -$msg _error= ' No temp directory found '; the Break; + Case7: A Case8: the$msg _error= ' System error '; + Break; - } $Exit($msg _error); $ } -$filename=$fileInfo[' Name ']; -//gets the file name extension the$ext=Strtolower(substr($filename,Strrpos($filename,'.') +1)); -//define an extension that allows uploadingWuyi$allowExt=Array(' txt ', ' HTML ', ' PNG ', ' gif ', ' JPEG '); the//detecting the type of upload file -if(!In_array($ext,$allowExt)){ WuExit(' Upload file type error '); - } About $ -//detecting the size of a file -$maxSize=2097152; -if($fileInfo[' Size ']>$maxSize){ AExit(' Upload file too large '); + } the -//detects if an HTTP post is being uploaded $if(!Is_uploaded_file($fileInfo[' Tmp_name '])){ theExit(' file is not submitted via HTTP POST. ')); the } the the//ensure file name is unique and prevent overwriting of files of the same name -$uniqName=MD5(uniqid(Microtime(true),true)).'.'.$ext; in the//defines the folder under which to save, if no folder is created the$path= ' uploads '; Aboutif(!file_exists($path)){ themkdir($path, 0777,true); thechmod($path, 0777); the } +$destination=$path.' /'.$uniqName; - the//move files to the directory you want to saveBayiif(! @Move_uploaded_file($fileInfo[' Tmp_name '],$destination)){ theExit(' File upload failed '); the } - -Echo' Upload success '; the the } the?>
The above describes the php file upload of a single file upload, including the content, I hope the PHP tutorial interested in a friend helpful.