function save_after($aid) { //$tag=preg_replace('/\s+/',' ',trim(front::$post['tag'])); $tags=explode(',',trim(front::$post['tag'])); //var_dump($tags); $tag_table=new tag(); $arctag_table=new arctag(); foreach($tags as $tag) { if($tag) if(!$tag_table->getrow('tagname="'.$tag.'"')) $tag_table->rec_insert(array('tagname'=>$tag)); $tag=$tag_table->getrow('tagname="'.$tag.'"'); $arctag_table->rec_replace(array('aid'=>$aid,'tagid'=>$tag['tagid'])); } //exit; $doit = false; if(session::get('attachment_id') ||front::post('attachment_id')) { $attachment_id=session::get('attachment_id')?session::get('attachment_id'):front::post('attachment_id'); $attachment=new attachment(); $attachment->rec_update(array('aid'=>$aid,'intro'=>front::post('attachment_intro')),$attachment_id); $doit = true; if(session::get('attachment_id')) session::del('attachment_id'); } if(front::post('attachment_path') != '' && $doit == false) { $attachment=new attachment(); $attachment->rec_insert(array('aid'=>$aid,'path'=>front::post('attachment_path'),'intro'=>front::post('attachment_intro'),'adddate'=>date('Y-m-d H:i:s'))); $doit = false; } if(front::post('_ranks')) { $_ranks=serialize(front::post('_ranks')); $rank=new rank(); if(is_array($rank->getrow(array('aid'=>$aid)))) $rank->rec_update(array('ranks'=>$_ranks),'aid='.$aid); else $rank->rec_insert(array('aid'=>$aid,'ranks'=>$_ranks)); } else { $rank=new rank(); $rank->rec_delete('aid='.$aid); } if(front::post('vote')) { $votes=front::$post['vote']; $images=front::$post['vote_image']; $vote=new vote(); $_vote=$vote->getrow('aid='.$aid); if(!$_vote) $_vote=array('aid'=>$aid); $_vote['titles']=serialize($votes); $_vote['images']=serialize($images); $vote->rec_replace($_vote,$aid); } }
function uploadfile_action() { $res=array(); $uploads=array(); if (is_array($_FILES)) { $upload=new upload(); $upload->dir='attachment'; $upload->max_size=config::get('upload_max_filesize')*1024*1024; $attachment=new attachment(); $_file_type=str_replace(',','|',config::get('upload_filetype')); $upload->type = explode('|',$_file_type); foreach ($_FILES as $name=>$file) { $res[$name]['size']=ceil($file['size'] / 1024); if ($file['size'] >$upload->max_size) { $res[$name]['code']="alert('附件超过上限(".ceil($upload->max_size / 1024)."K)!');"; break; } if (!front::checkstr(@file_get_contents($file['tmp_name']))) { $res[$name]['code']=lang('上传失败!附件没有通过验证!'); break; } if (!$file['name'] ||!preg_match('/\.('.$_file_type.')$/',$file['name'])) continue; $uploads[$name]=$upload->run($file); if (!$uploads[$name]) { $res[$name]['code']="alert('".'附件保存失败!'.");"; break; } $res[$name]['name']=$uploads[$name]; $res[$name]['type']=$file['type']; $attachment->rec_insert(array('path'=>$uploads[$name],'intro'=>front::post('attachment_intro'),'adddate'=>date('Y-m-d H:i:s'))); $res[$name]['id']=$attachment->insert_id(); $rname=preg_replace('%(.*)[\\\\\/](.*)_\d+(\.[a-z]+)$%i','$2$3',$uploads[$name]); $res[$name]['code']=" document.form1.attachment_id.value=data[key].id; if(!document.form1.attachment_intro.value) { document.form1.attachment_intro.value='$rname'; } document.form1.attachment_path.value=data[key].name; get('attachment_path_i').innerHTML=data[key].name; get('file_info').innerHTML='附件已保存!大小为:'+data[key].size+'K '; "; session::set('attachment_id',$res[$name]['id']); } } echo json::encode($res); }