php 文件图片上传,php 文件图片上传类程序

upx.php文件

?>

uploadx.php类文件

使用方法:

html表单页

-------------------------------------------------------------------------

-------------------------------------------------------------------------

upload.php处理页

-------------------------------------------------------------------------

)

$upx->uploadx_save = "temp";                //保存文件目录(上传文件保存目录可以是相对路径也可以是绝对路径)

$upx->uploadx_type = 'jpg|gif|png|swf';    //允许上传类型(根据后缀限制上传类型,每个后缀用"|"隔开)

$upx->uploadx_size = "1024";                //允许上传大小(单位是kb。例:1024=1024kb)

$upx->uploadx_name = time();                //上传后文件名(可自定义。例:date("y-m-d",time()))

if($upx->file()){

echo "上传成功

";

echo "名称->".$upx->file['name']."

";

echo "路径->".$upx->file['path']."

";

echo "大小->".$upx->file['size']."

";

echo "类型->".$upx->file['type']."

";

echo "时间->".$upx->file['time']."

";

echo "结果->".$upx->file['info']."

";

}else{

echo $upx->file['info'];

}

-------------------------------------------------------------------------

*/

class uploadx {

public $uploadx_form; //表单控件名称

public $uploadx_save; //保存文件目录

public $uploadx_type; //允许上传类型

public $uploadx_size; //允许上传大小

public $uploadx_name; //上传后文件名

function __construct(){//初始化函数

$this->uploadx_form = 'attach';

$this->uploadx_save = 'temp';

$this->uploadx_type = 'jpg|gif|png|swf|flv|rar|7z|zip|doc|docx|ppt|pptx|xls|xlsx|txt|pdf|wav|mp3|wma|rm|rmvb|wmv';

$this->uploadx_size = '1024';

$this->uploadx_info = false;

}

function mkdirs($path , $mode = 0777){

$rootdir = '';

if(substr($path,0,1)=='/') $rootdir = $_server['document_root'];

$path = $rootdir . $path;

if(!is_dir($path)){

$this->mkdirs(dirname($path),$mode);

mkdir($path,$mode);

}

return true;

}

function file(){

if(!isset($_files[$this->uploadx_form])){

$this->file = array('file'=>false,'info' => '上传错误!请检查表单上传控件名称['.$this->uploadx_form.']是否正确!');

return false;

}

switch($_files[$this->uploadx_form]['error']){

case 1:

$this->file = array('file'=>false,'info' => '指定上传的文件大小超出服务器限制!');

return false;

break;

case 2:

$this->file = array('file'=>false,'info' => '指定上传的文件大小超出表单限制!');

return false;

break;

case 3:

$this->file = array('file'=>false,'info' => '只有部份文件被上传,文件不完整!');

return false;

break;

case 4:

$this->file = array('file'=>false,'info' => '您没有选择上传任何文件!');

return false;

}

$postfix = pathinfo($_files[$this->uploadx_form]['name'], pathinfo_extension);

if(stripos($this->uploadx_type,$postfix)===false){

$this->file = array('file'=>false,'info' => '指定上传的文件类型超出限制,允许上传文件类型:'.$this->uploadx_type);

return false;

}

if(round($_files[$this->uploadx_form]['size']/1024)>$this->uploadx_size){

$this->file = array('file'=>false,'info' => '指定上传的文件超出大小限制,文件上传限制范围:'.$this->uploadx_size.'kb');

return false;

}

if($this->mkdirs($this->uploadx_save)){

$this->uploadx_name = isset($this->uploadx_name) ? $this->uploadx_name.'.'.$postfix : $_files[$this->uploadx_form]['name'];

if(!@move_uploaded_file($_files[$this->uploadx_form]['tmp_name'],$this->uploadx_save.'/'.$this->uploadx_name)){

$this->file = array('file'=>false,'info' => '上传文件保存过程中出现错误,请检查路径或目录权限.');

return false;

}

}else{

$this->file = array('file'=>false,'info' => '服务器目录不存在,自动创建目录失败,请检查是否有权限!');

return false;

}

@chmod($this->uploadx_save.'/'.$this->uploadx_name,0777);

$this->file = array(

'file' => true,

'name' => $this->uploadx_name,

'path' => $this->uploadx_save.'/'.$this->uploadx_name,

'size' => $_files[$this->uploadx_form]['size'],

'type' => $postfix,

'time' => time(),

'info' => '上传成功!'

);

return true;

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值