#1 setlt
首先声明非本人原创,不过这个类的确不错,除了文件上传的基本功能,还可以产生缩略图及打水印等功能,经本人测试,可以结合speendPHP很简单的使用。喜欢的,可以试试。uploadFile.rar2009-12-24 21:45:06
2009-12-24 21:45:06
2009-12-24 22:51:58
2009-12-25 08:46:01
2009-12-25 09:00:27
2009-12-25 15:04:25
import("uploadFile.php");
class ToolBox extends spController {
//上传类测试
function upFile(){
$this->title='文件上传';
if($this->spArgs('up')){
$upFlie=new uploadFile();
$result=$upFlie->upload_file($_FILES['upfile']);
$msg=$upFlie->errmsg;
if($result){
$this->success=$msg;
}else {
$this->errmsg=$msg;
}
}
}
}
?>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">{$title} {$title}
{if $success}
{elseif $errmsg}{$errmsg} 重新上传
{else}
2009-12-25 16:18:28
2009-12-25 17:52:13
2009-12-25 20:53:09
2010-01-02 17:24:21
2010-01-03 01:13:30
2010-01-18 16:32:42
2010-02-16 23:59:08
2010-02-18 19:33:57
2010-02-21 20:24:30
2010-02-23 12:26:45
感谢 setlt 朋友的教程!
这里补充一下,由于预设了“'include_path'=>array( APP_PATH.'/plug',),” 的路 ...
jake 发表于 2009-12-25 17:52
2010-03-01 22:55:49
2010-03-02 08:55:50
2010-03-03 13:50:55
2010-03-20 18:25:55
2010-03-28 11:34:58
看看upload类的构造函数
__construct($save_path = './upload/',$file_name = 'date',$allow_types = '')
...
jake 发表于 2010-3-2 08:55
2010-04-01 23:17:44
$uparray=array('./upload/','date');
$upFlie=spClass('uploadFile',$uparray);
按照 jake的 ...
shinid8210 发表于 2010-4-1 23:17
2010-04-02 11:16:43
2010-05-21 14:53:44
public function __construct($upconfig) {
$this->file_name = $upconfig['filename'] ? $upconfig['filename'] : 'date';//重命名方式代表以时间命名,其他则使用给予的名称
$this->save_path = (preg_match('/\/$/',$upconfig['filepath'])) ? $upconfig['filepath'] : $upconfig['filepath'] . '/';
$this->allow_types = $upconfig['filetype'] ? $upconfig['filetype'] : 'jpg|gif|png|zip|rar' ;
$this->max_size = $upconfig['filesize'] ? $upconfig['filesize'] : 2048000 ;
} public function upload_file($files) {
$name = $files['name'];
$type = $files['type'];
$size = $files['size'];
$tmp_name = $files['tmp_name'];
$error = $files['error'];
switch ($error) {
case 0 : $this->errmsg = '';
break;
case 1 : $this->errmsg = '超过了php.ini中文件大小';
break;
case 2 : $this->errmsg = '超过了MAX_FILE_SIZE 选项指定的文件大小';
break;
case 3 : $this->errmsg = '文件只有部分被上传';
break;
case 4 : $this->errmsg = '没有文件被上传';
break;
case 5 : $this->errmsg = '上传文件大小为0';
break;
default : $this->errmsg = '上传文件失败!';
break;
}
if($error == 0 && is_uploaded_file($tmp_name)) {
//检测文件类型
if($this->check_file_type($name) == FALSE){
return FALSE;
}
//检测文件大小
if($size > $this->max_size){
$this->errmsg = '上传文件'.$name.'太大,最大支持'.ceil($this->max_size/1024).'kb的文件';
return FALSE;
}
$this->set_save_path();//设置文件存放路径
if($this->file_name=='date'){
$new_name = date('YmdHis').'.'.$this->ext;//设置新文件名
}elseif($this->file_name=='md5'){
$new_name = md5(time().$name).'_'.time().'.'.$this->ext;//设置新文件名
}else{
$new_name = $this->file_name.'.'.$this->ext;
}
$this->uploaded = $this->save_path.$new_name;//上传后的文件名
//移动文件
if(move_uploaded_file($tmp_name,$this->uploaded)){
$this->errmsg = '文件'.$this->uploaded.'上传成功!';
return array('nn'=>$new_name,'fs'=>$size,'ft'=>$type,'fn'=>$name);
}else{
$this->errmsg = '文件'.$this->uploaded.'上传失败!';
return FALSE;
}
}
}
function upload(){
/* 或者放在CONFIG,然后通过spExt 调用 */
$upconfig = array(
'filename'=> 'md5', //文件名类型 (date|md5)
'filepath'=> './attach/', //文件目录
'filesize'=> '1024000', //文件最大
'filetype'=> 'jpg|jpeg|gif|png', //文件类型
);
$fileinfo = spClass('uploadFile',$upconfig)->upload_file($_FILES['fileinfo']);
if (is_array($fileinfo)){
dump($fileinfo);
//$fileinfo 信息入库操作 略~~~~~~
$this->error('已上存',spUrl('pic', 'index'));
}else{
$this->error('上存失败',spUrl('pic', 'index'));
}
}
2010-05-21 15:39:55
2010-05-21 15:43:24
2010-06-01 22:10:29
2010-06-26 12:56:37
2010-07-25 15:57:10
$uparray=array('./upload/','date');
$upFlie=spClass('uploadFile',$uparray);
按照 jake的 ...
shinid8210 发表于 2010-4-1 23:17
2010-08-02 16:43:16
2010-08-04 11:21:51
2010-08-18 20:30:53
2010-08-19 22:57:25
2010-09-25 10:28:24
'include_path' => array(
APP_PATH.'/include',
APP_PATH.'/plug',
), // 用户程序扩展类载入路径
class touxiang extends spController {
//上传类测试
function upFile(){
$this->title="文件上传";
if($this->spArgs("up")){
$uparray=array('filepath'=>APP_PATH . '/images/touxiang','filename'=>'date');
$upFlie=spClass("uploadFile",$uparray);
$result=$upFlie->upload_file($_FILES["upfile"]);
$msg=$upFlie->errmsg;
if($result){
$this->success=$msg;
$this->newname=$result["nn"];
}else {
$this->errmsg=$msg;
}
}
}
}
{$title} {$title}HELLO
{if $success}{$success} 继续上传
{elseif $errmsg}{$errmsg} 重新上传
{else}
{/if}
2010-12-08 00:01:53
2010-12-17 19:33:34
function upFile(){
$this->title='文件上传';
if($this->spArgs("up")){
$uparray=array('filepath'=>APP_PATH . '/themes/uploads/','filename'=>'date');
$upFlie=spClass("uploadFile",$uparray);
$result=$upFlie->upload_file($_FILES["upfile"]);
$msg=$upFlie->errmsg;
if($result){
//dump($result); //输出上传成功的返回值 'nn'=>new_name,'fs'=>$size,'ft'=>$type,'fn'=>$name
$this->success = $msg;//赋值给模版成功提示
$this->newname = $result["nn"];//赋值上传成功文件名。
$this->pic_path = "/themes/uploads/".date('Ym').'/'.$this->newname;
//echo "";
}else {
$this->errmsg = $msg;
}
}
$this -> display('test/adupfile.html');如何将上传图片的ID,也就是$this->pic_path发送到嵌套iframe这个页面而写入数据库?
<{$title}>
<{if $success}>
<{$pic_path}>文件上传成功
<{elseif $errmsg}><{$errmsg}> 重新上传
<{else}>
<{/if}>
2011-01-22 22:57:01
2011-01-23 03:49:58
2011-02-08 22:20:42
2011-02-08 22:21:04
2011-07-14 16:28:36
2011-07-17 19:20:18
2011-07-17 19:26:17
2011-07-19 11:59:58
2011-07-21 11:27:20
2011-07-21 11:28:10
2011-08-22 19:58:36
2011-10-25 15:47:36
2011-11-16 11:17:25
2011-11-18 14:44:12
2011-11-18 14:50:06
2012-02-29 09:14:25
2012-08-30 23:49:57
2013-01-22 17:44:17
2013-03-20 22:16:51
2013-06-22 12:51:01
2013-10-12 13:30:16
2013-10-22 13:36:32
2014-08-13 16:57:37
2015-02-27 17:22:14
lvqing 发表于 2015-2-27 17:22
jake 老大,spClass 实例化类时,需要传入初始参数时,应该怎么写?一直找不到例子 ...
2015-02-27 17:36:54
2015-02-28 11:08:20
2015-08-02 09:43:01
2016-03-03 21:56:35
2016-05-16 14:25:18