将子窗口的方法转到ajax控制器

master
liuweiwen 5 years ago
parent 854ab9f509
commit e243675bcc

@ -469,4 +469,57 @@ class AjaxController extends ThinkController{
}
public function addfile()
{
$this->meta_title = '文档添加';
$template = I('t');
$template = $template ?: 'Partner/addfile';
return $this->display($template);
}
//处理上传图片
public function saveFile()
{
$path = '/Uploads/';
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 0 ;// 设置附件上传大小
$upload->exts = '';// 设置附件上传类型
$upload->rootPath = '.'.$path; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
// 上传文件
$info = $upload->upload();
// dump($info);
if(!$info) {// 上传错误提示错误信息
$msg = $upload->getError();
$array= array('status' => 0, 'info' => $msg);
}else{// 上传成功
$array=array(
"info"=>"上传成功",
"status"=>1,
"file_path"=>$path.$info['file']['savepath'].$info['file']['savename'],
"file_name"=>$_POST['file_name'],
"file_type"=>$_FILES['file']['type'],
"file_size"=>$_FILES['file']['size'],
"upload_time"=>date("Y-m-d H:i:s",time())
);
}
$this->ajaxReturn($array);
}
//删除图片
public function delFile()
{
$id = $_REQUEST['id'];
$index = $_REQUEST['index'] ?: false;
$file_path = $_REQUEST['file_path'] ?: false;
if($id == 0){
//未存入数据库,不用管
unlink("./".$file_path);
$this->ajaxReturn(array(
'status' => 1,
'info' => "删除成功"
));
}
# code...
}
}

@ -412,55 +412,6 @@ class PartnerController extends ThinkController
$this->success('删除成功', U('lists'));
}
public function addfile()
{
$this->meta_title = '文档添加';
return $this->display();
}
//处理上传图片
public function saveFile()
{
$path = '/Uploads/';
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 0 ;// 设置附件上传大小
$upload->exts = '';// 设置附件上传类型
$upload->rootPath = '.'.$path; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
// 上传文件
$info = $upload->upload();
// dump($info);
if(!$info) {// 上传错误提示错误信息
$msg = $upload->getError();
$array= array('status' => 0, 'info' => $msg);
}else{// 上传成功
$array=array(
"info"=>"上传成功",
"status"=>1,
"file_path"=>$path.$info['file']['savepath'].$info['file']['savename'],
"file_name"=>$_POST['file_name'],
"file_type"=>$_FILES['file']['type'],
"file_size"=>$_FILES['file']['size'],
"upload_time"=>date("Y-m-d H:i:s",time())
);
}
$this->ajaxReturn($array);
}
//删除图片
public function delFile()
{
$id = $_REQUEST['id'];
$index = $_REQUEST['index'] ?: false;
$file_path = $_REQUEST['file_path'] ?: false;
if($id == 0){
//未存入数据库,不用管
unlink("./".$file_path);
$this->ajaxReturn(array(
'status' => 1,
'info' => "删除成功"
));
}
# code...
}
}

@ -186,7 +186,7 @@
<tr>
<td class="l noticeinfo">文档管理</td>
<td class="r table_radio">
<input type="button" class="coin-detail" data-url="{:U('Partner/addfile')}" value="添加"
<input type="button" class="coin-detail" data-url="{:U('Ajax/addfile')}" value="添加"
style="border-radius:5%;background: #fff;color: #333;font-weight: 400;border: 1px solid #777;width: 100px;height: 35px">
</td>
</tr>
@ -352,7 +352,7 @@
console.log(index);
var id = 0;
$.ajax({
url:"{:U('Partner/delFile')}",
url:"{:U('Ajax/delFile')}",
type:"post",
data:{
"id":0,

@ -58,7 +58,7 @@
formData.append("file", document.getElementById("fileinput").files[0]);
var index = layer.load();
$.ajax({
url:"{:U('Partner/saveFile')}",
url:"{:U('Ajax/saveFile')}",
type:"post",
data:formData,
processData:false,

@ -186,7 +186,7 @@
<tr>
<td class="l noticeinfo">文档管理</td>
<td class="r table_radio">
<input type="button" class="coin-detail" data-url="{:U('Partner/addfile')}" value="添加"
<input type="button" class="coin-detail" data-url="{:U('Ajax/addfile')}" value="添加"
style="border-radius:5%;background: #fff;color: #333;font-weight: 400;border: 1px solid #777;width: 100px;height: 35px">
</td>
</tr>
@ -359,7 +359,7 @@
console.log(index);
var id = 0;
$.ajax({
url:"{:U('Partner/delFile')}",
url:"{:U('Ajax/delFile')}",
type:"post",
data:{
"id":0,

Loading…
Cancel
Save