php 图片上传 下载,php文件图片上传类 - php上传下载

/*

* created on 2010-6-21

*

* the class for image to upload

*

* made by s71ence

*

* @$user_id

* @$max_file_size

* @$max_image_side

* @$destination_folder

*

* return:

* @$_cookie['img_path']

* @$img_unfind

* @$img_type

* @$mkdir_warry

* @$img_side_too_big

* @$img_exist

* @$img_move

* @$img_upload_sucess

*/

代码如下 复制代码

header('content-type:text/html;charset=utf-8');

classimage_uploadextendsfn_function

{

private$user_id;

private$max_file_size;//allow the image's size

private$max_image_side;//allow the image's side

private$destination_folder;//image's storage path

private$img_preview;

private$img_preview_size;

private$cookie_set;//the cookie's name

function__construct($user_id,$max_file_size,$max_image_side,$destination_folder,$img_preview,$img_preview_size,$cookie_set)

{

$this->user_id=$user_id;

$this->max_file_size=$max_file_size;

$this->max_image_side=$max_image_side;

$this->destination_folder=$destination_folder;

$this->img_preview=$img_preview;

$this->img_preview_size=$img_preview_size;

$this->cookie_set=$cookie_set;

$this->get_date();

$this->get_image_type();

}

privatefunctionget_date()

{

$this->date=fn_function::get_server_date();

return$this->date;

}

functionget_image_type()

{

$this->up_img_types=array(

'image/jpg',

'image/jpeg',

'image/png',

'image/pjpeg',

'image/gif',

'image/bmp',

'image/x-png'

);

return$this->up_img_types;

}

functionupload_image()

{

if($_server['request_method'] =='post')

{

//check the iamge is exist

if(!is_uploaded_file($_files["upfile"]["tmp_name"]))

{

return$img_unfind=fn_function::alert_msg('图片不存在!');

exit;

}

$file=$_files["upfile"];

//check the iamge's size

if($this->max_file_size 

{

return$img_side_too_big=fn_function::alert_msg('图片大小超过系统允许最大值!');

exit;

}

//check the iamge's type

if(!in_array($file["type"],$this->up_img_types))

{

return$img_type=fn_function::alert_msg('图片类型不符!');

exit;

}

if(!file_exists($this->destination_folder))

{

if(!fn_function::mkdirs($this->destination_folder))

{

return$mkdir_warry=fn_function::alert_msg('目录创建失败!');

exit;

}

}

$file_name=$file["tmp_name"];

$image_size=getimagesize($file_name);

$pinfo=pathinfo($file["name"]);

$file_type=$pinfo['extension'];

$destination=$this->destination_folder.time().".".$file_type;

setcookie($this->cookie_set,$destination);

if($image_size[0]>$this->max_image_side ||$image_size[1]>$this->max_image_side)

{

return$img_side_too_big=fn_function::alert_msg('图片分辨率超过系统允许最大值!');

exit;

}

$overwrite="";

if(file_exists($destination) &&$overwrite!= true)

{

return$img_exist=fn_function::alert_msg('同名文件已经存在了!');

exit;

}

if(!move_uploaded_file ($file_name,$destination))

{

return$img_move=fn_function::alert_msg('移动文件出错!');

exit;

}

$img_upload_sucess="上传成功
";

if($this->img_preview==1)

{

$img_src="img_preview_size)." height=".($image_size[1]*$this->img_preview_size);//开源代码phpfensi.com

$img_upload_sucess.=$img_src;

}

return$img_upload_sucess;

}

}

function__destruct()

{

//clear

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值