Commit ac69cd57 authored by zhuwei's avatar zhuwei

bug

parent 97cd240a
...@@ -201,35 +201,36 @@ class News extends Basic ...@@ -201,35 +201,36 @@ class News extends Basic
} }
/**
* 附件下载并替换文件名
*
*/
public function downloadFile() { public function downloadFile() {
$data[]=['file_name'=>'12','file_former_name'=>'44']; if (empty($this->params['file_id'])) {
$data[]=['file_name'=>'12','file_former_name'=>'44']; echo "<script>alert('文件不存在')</script>";
return $this->response(200, $data); }
$field = 'id,file_name,annex_file_name';
$where['status'] = 0;
// dump(666);exit; $where['id'] = $this->params['file_id'];
// $this->params['file_name']= '20181203/20181203110021473.jpg'; $m_file = new SFile();
// $this->params['file_former_name']='ceshi.jpg'; $data = $m_file->getFileById($field, $where);
// if (empty($this->params['file_name']) or empty($this->params['file_former_name'])) {
// echo "<script>alert('文件不存在')</script>";
// } $file_name = $data['file_name'];
// $file_former_name = $data['file_former_name'];
// $file_name = $this->params['file_name'];
// $file_former_name = $this->params['file_former_name']; $filepath = ROOT_PATH . 'public/static/business_school_file/'.$file_name;
// if(file_exists($filepath)){
// $filepath = ROOT_PATH . 'public/static/business_school_file/'.$file_name; header("Content-type:application/octet-stream");
// if(file_exists($filepath)){ $filename = basename($filepath);
// header("Content-type:application/octet-stream"); header("Content-Disposition:attachment;filename = {$file_former_name}");
// $filename = basename($filepath); header("Accept-ranges:bytes");
// header("Content-Disposition:attachment;filename = {$file_former_name}"); header("Accept-length:".filesize($filepath));
// header("Accept-ranges:bytes"); readfile($filepath);
// header("Accept-length:".filesize($filepath)); }else{
// readfile($filepath); echo "<script>alert('文件不存在')</script>";
// }else{ }
// echo "<script>alert('文件不存在')</script>";
// }
} }
} }
\ No newline at end of file
...@@ -76,4 +76,13 @@ class SFile extends BaseModel ...@@ -76,4 +76,13 @@ class SFile extends BaseModel
->order($order) ->order($order)
->select(); ->select();
} }
public function getFileById($field = '', $params = '')
{
return $this
->field($field)
->where($params)
->find();
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment