PHP File Upload single file upload,
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 at if($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)){ Wu Exit(' Upload file type error '); - } About $ - //detecting the size of a file - $maxSize=2097152; - if($fileInfo[' Size ']>$maxSize){ A Exit(' Upload file too large '); + } the - //detects if an HTTP post is being uploaded $ if(!Is_uploaded_file($fileInfo[' Tmp_name '])){ the Exit(' 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 '; About if(!file_exists($path)){ the mkdir($path, 0777,true); the chmod($path, 0777); the } + $destination=$path.' /'.$uniqName; - the //move files to the directory you want to saveBayi if(! @Move_uploaded_file($fileInfo[' Tmp_name '],$destination)){ the Exit(' File upload failed '); the } - - Echo' Upload success '; the the } the?>
http://www.bkjia.com/PHPjc/1036616.html www.bkjia.com true http://www.bkjia.com/PHPjc/1036616.html techarticle php File Upload single file upload, in order to be simple, the php file and form form is written in a file. php Single File upload----1! DOCTYPE HTML 2 HTML 3 Head 4 meta charset= "UTF-8" ...