php代码添加图片,php文件上传代码(带图片预览效果)

//删除文件

function removefile($filepath,$path)

{

if(!empty($filepath)&&file_exists('../'.$path.$filepath))

{

unlink('../'.$path.$filepath);

return true;

}

else

{

return false;

}

}

//获取图片类型

function get_filetype($path)

{

$pos=strrpos($path,'.'); //在第一个字串中查找第二个字串最后出现的位置

if($pos!==false)

{

return substr($path,$pos); //截取后缀名

}

else

{

return ''; //返回空

}

}

//错误方法

function showerror($files)

{

if(isset($files['error']))  //判断有没有错误先

{

$php_maxsize=ini_get('upload_max_filesize'); //获取系统配置图片最大值

$htm_maxsize='20m';  //默认为2m

$msg="";            //格式化对话框

if($files['error']==0)   //0:类型错误

{

if(!$this->check_img_type($files['type']))

{

$msg='上传图片类型不对';

}

}

else if($files['error']==1)  //1:超过系统最大值

{

$msg="上传图片太大,最大为$php_maxsize";

}

else if($files['error']==2)   //2:超过默认值

{

$msg="上传图片超过$htm_maxsize";

}

}

}

//图片类型

function check_img_type($imgtype)

{

switch($imgtype)

{

case'image/pjpeg':

case'image/gif':

case'image/png':

case'swf':

}

return 1;

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值