控制器:
pc_base::load_sys_class('attachment','',0); //加载类
pc_base::load_app_func('global','attachment'); //加载函数库
//获取参数、限制条件
$siteid = $this->get_siteid();
$site_setting = get_site_setting($siteid);
$site_allowext = $site_setting['upload_allowext'];
//文件上传
$attachment = new attachment($module,$catid,$siteid);
$attachment->set_userid($this->userid);
$a = $attachment->upload('importfile',$site_allowext);
$upload_root = pc_base::load_config('system','upload_path'); //载入配置
if($a){
$filepath = $attachment->uploadedfiles[0]['filepath'];
$inputFileName = $upload_root . $filepath ;//上传文件
if( $inputFileName == null ) showmessage(L('attachment_upload_failure', '', 'attachment'));
}else{
showmessage(L('attachment_upload_failure', '', 'attachment'));
}
模版
<input type="file" name='importfile' value=""/> //这里的name 要和 上面的 $attachment->upload(); 第一个参数相同
<input type="submit" name="do_insert" class="button" value="<?php echo L('确认导入')?>" />