php文件上传(强大文件图片上传类)
2013-09-05 19:25
726 查看
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');
class image_upload extends fn_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();
}
private function get_date()
{
$this->date=fn_function::get_server_date();
return $this->date;
}
function get_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;
}
function upload_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 < $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="<font color=red face=微软雅黑>上传成功</font><br>";
if($this->img_preview==1)
{
$img_src="<img src="".$destination."" width=".($image_size[0]*$this->img_preview_size)." height=".($image_size[1]*$this->img_preview_size);
$img_upload_sucess.=$img_src;
}
return $img_upload_sucess;
}
}
function __destruct()
{
//clear
}
}
这款文件上传实用代码,可以方便的上传你指定的文件或图片,同时也可以快速的限制上传图片文件类或大小。
/*
* 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');
class image_upload extends fn_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();
}
private function get_date()
{
$this->date=fn_function::get_server_date();
return $this->date;
}
function get_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;
}
function upload_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 < $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="<font color=red face=微软雅黑>上传成功</font><br>";
if($this->img_preview==1)
{
$img_src="<img src="".$destination."" width=".($image_size[0]*$this->img_preview_size)." height=".($image_size[1]*$this->img_preview_size);
$img_upload_sucess.=$img_src;
}
return $img_upload_sucess;
}
}
function __destruct()
{
//clear
}
}
相关文章推荐
- php判断上传的Excel文件中是否有图片及PHPExcel库认识
- php图片上传之文件安全
- PHP远程上传web与图片文件分离
- PHP ThinkPHP ,上传文件(图片),制作缩略图,批量上传文件
- php 上传文件|图片 时候报错 Allowed memory size of 20971520
- 用php怎么上传图片文件呢?
- php中上传图片文件,并且以上传时的时间戳命名文件,并将文件的路径存在session中以便使用。
- PHP文件上传类,包含批量上传
- php+ajax实现图片文件上传实例代码
- js实现图片文件上传预览 | 黄乔国PHP
- 使用PhpMysql实现图片文件上传下载
- nginx+php 上传含有php脚本的木马图片文件的漏洞解决
- php 上传文件|图片 时候报错 Allowed memory size of 20971520
- php实现图片上传与文件上传的实现代码实例
- php判断文件上传图片格式的实例详解
- PHP文件上传小结(乱码,移动失败,权限,显示图片)
- php判断上传文件是不是图片,如果是,返回图片格式
- 图片(文件)上传(BROWSER+PHP)
- 用yourphp uploadFile.class.php上传图片出现非法图像文件无法上传
- php图片文件上传详细分析