PHP's most original upload file function

Source: Internet
Author: User

<?PHP$upload _file=$_files[' Upload_file '] [' Tmp_name '];$upload _file_name=$_files[' Upload_file '] [' Name '];//uploaded filename//Get file suffix name$temp _arr=Explode(".",$upload _file_name);$file _ext=Array_pop($temp _arr);$file _ext=Trim($file _ext);$file _ext=Strtolower($file _ext);//$file The suffix of the _ext file$file _name_ext= Time().Rand(100, 999). '. '.$file _ext;$file _ext_arr=Array(' rar ', ' zip ', ' txt ', ' Doc ', ' ppt ', ' xls ');if(!In_array($file _ext,$file _ext_arr)){//not in the allowed range    Echo"The uploaded file is not in the correct format"; Exit;}$upload _file_size=$_files[' Upload_file '] [' Size '];if($upload _file){    $file _size_max= 100*1000*1000;//limit file Upload maximum capacity (bytes)    $webroot=$cfg[Path][root]; $store _dir=$webroot." upfile/isclass/file/";//where to store the uploaded files    $accept _overwrite= 1;//whether to allow overwriting the same file//check file size    if($upload _file_size>$file _size_max) {        Echo"Sorry, your file size is greater than the rule."; Exit; }    //check read and write files    if(file_exists($store _dir.$upload _file_name) &&!$accept _overwrite) {        Echo"Files with the same file name exist"; Exit; }    //copy files to the specified directory    if(!Move_uploaded_file($upload _file,$store _dir.$file _name_ext)) {        Echo"Failed to copy file"; Exit; }}  

PHP's most original upload file function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.