Commit ac69cd57 authored by zhuwei's avatar zhuwei

bug

parent 97cd240a
......@@ -201,35 +201,36 @@ class News extends Basic
}
/**
* 附件下载并替换文件名
*
*/
public function downloadFile() {
$data[]=['file_name'=>'12','file_former_name'=>'44'];
$data[]=['file_name'=>'12','file_former_name'=>'44'];
return $this->response(200, $data);
// dump(666);exit;
// $this->params['file_name']= '20181203/20181203110021473.jpg';
// $this->params['file_former_name']='ceshi.jpg';
// if (empty($this->params['file_name']) or empty($this->params['file_former_name'])) {
// echo "<script>alert('文件不存在')</script>";
// }
//
// $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)){
// header("Content-type:application/octet-stream");
// $filename = basename($filepath);
// header("Content-Disposition:attachment;filename = {$file_former_name}");
// header("Accept-ranges:bytes");
// header("Accept-length:".filesize($filepath));
// readfile($filepath);
// }else{
// echo "<script>alert('文件不存在')</script>";
// }
if (empty($this->params['file_id'])) {
echo "<script>alert('文件不存在')</script>";
}
$field = 'id,file_name,annex_file_name';
$where['status'] = 0;
$where['id'] = $this->params['file_id'];
$m_file = new SFile();
$data = $m_file->getFileById($field, $where);
$file_name = $data['file_name'];
$file_former_name = $data['file_former_name'];
$filepath = ROOT_PATH . 'public/static/business_school_file/'.$file_name;
if(file_exists($filepath)){
header("Content-type:application/octet-stream");
$filename = basename($filepath);
header("Content-Disposition:attachment;filename = {$file_former_name}");
header("Accept-ranges:bytes");
header("Accept-length:".filesize($filepath));
readfile($filepath);
}else{
echo "<script>alert('文件不存在')</script>";
}
}
}
\ No newline at end of file
......@@ -76,4 +76,13 @@ class SFile extends BaseModel
->order($order)
->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