- class upphoto{
- public $previewsize=0.125 ; //Preview image ratio
- public $preview=0 ; //Whether to generate a preview, 1 if yes, 0 if not
- public $datetime; //Random number
- public $ph_name; //Upload image file name
- public $ph_tmp_name; //Temporary image file name
- public $ph_path="../userimg/"; //Upload file storage path
- public $ph_type; //Image type
- public $ph_size; //Image size
- public $imgsize; //Upload image size, used to determine display ratio
- public $al_ph_type=array(image/jpg,image /jpeg,image/png,image/pjpeg,image/gif,image/bmp,image/x-png); //Allow image type to upload
- public $al_ph_size=1000000; //Allow file size to upload
- function __construct(){
- $this->set_datatime();
- }
- function set_datatime(){
- $this->datetime=date("YmdHis");
- }
- //Get file type
- function get_ph_type($phtype){
- $this->ph_type=$phtype;
- }
- //Get file size
- function get_ph_size($phsize){
- $this ->ph_size=$phsize."
";
- }
- //Get the upload temporary file name
- function get_ph_tmpname($tmp_name){
- $this->ph_tmp_name=$tmp_name;
- $this->imgsize=getimagesize($tmp_name);
- }
- //Get the original text File name
- function get_ph_name($phname){
- $this->ph_name=$this->ph_path.$this->datetime.strrchr($phname,".") ; //strrchr gets the position where the point in the file last appeared
- //$this->ph_name=$this->datetime.strrchr($phname,"."); //strrchr gets the file The position where the point last appeared
- return $this->ph_name;
- }
- // Determine the uploaded file storage directory
- function check_path( ){
- if(!file_exists($this->ph_path)){
- mkdir($this->ph_path);
- }
- }
- //Determine whether the uploaded file exceeds the allowed size
- function check_size(){
- if($this->ph_size>$this->al_ph_size) {
- } $this->showerror("Uploaded image exceeds 2000KB");
- }
- }
- //Determine the file type
- function check_type(){
- if(!in_array($this->ph_type,$this->al_ph_type)){
- $this->showerror("Upload Wrong image type");
- }
- }
- //Upload image
- function up_photo(){
- if(! move_uploaded_file($this->ph_tmp_name,$this->ph_name)){
- $this->showerror("Error uploading file");
- }
- }
- //Picture preview
- function showphoto(){
- if($this->preview==1){
- if( $this->imgsize[0]>2000){
- $this->imgsize[0]=$this->imgsize[0]*$this->previewsize;
- ="{$this->ph_name}" width="{$this->imgsize[0]}" height="{$this->imgsize[1]}">");
- }
- }
- // Error message
- function showerror($errorstr){
- echo "";
- exit();
- }
- function save(){
- $this ->check_path();
- $this->check_size();
- $this->check_type();
- $this->up_photo( );
- $this->showphoto();
- }
- }
- ?>
-
http://www.bkjia.com/PHPjc/486216.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486216.htmlTechArticle?php class upphoto{ public $previewsize=0.125; //Preview image ratio public $preview=0; // Whether to generate a preview, 1 if yes, 0 if not public $datetime; //random number public $ph_name; //upload...