Implement the function of uploading pictures
date_default_timezone_set("PRC"); header("content-type:text/html;charset=utf-8"); require_once("./function1.php"); if (isset($_GET['act']) && ($_GET['act'] == "uploads")){ //Determine whether the uploaded file is legal if(!is_uploaded_file($_FILES['avator'][ tmp_name])){ msg("The uploaded file is illegal"); } //Determine the file size $allowed_size = 2*1024*1024; if($_FILES['avator']['size']> ;$allowed_size){ msg("The uploaded picture is too large, please modify it and re-upload it"); } //Judge the type $allowed_type = array("jpg","bmp","gif","jpeg ","png","zip","rar","txt"); $path_info_arr = pathinfo($_FILES['avator']['name']);//Get the array of file types $extension = strtolower($path_info_arr['extension']); if(!in_array($extension,$allowed_type)){ msg("The uploaded type is not allowed"); } //Rename if(!file_exists( "./uploads/")){ @mkdir("./uploads/",0777,true); } $new_name = date("YmdHis").rand(1000,9999).".".$ extension; //Move $res = move_uploaded_file($_FILES['avator']['tmp_name'],"./uploads/{$new_name}"); if($res){ echo "< ;a href='./uploads/{$new_name}'>View uploaded files";
}
}else{
?>
Please upload files
}
Copy code