<?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