[請益] 如何直接回傳檔案??
各位大大好︰
小弟想把檔案傳給手機應用, 但不想把檔案地址發給他, 於是做了一些麻煩的事情.......
public function downloadFileByFileToken_post() {
$fileToken = $this->input->post('FileToken');
$this->load->model('system_model');
$filePath = $this->system_model->getFilePathByFileToken($fileToken);
if (file_exists($filePath)) {
$path_parts = pathinfo($filePath);
$this->load->model('system_model');
$newFileName = $this->system_model->generateRandomString(16);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$newFileName.'.'.$path_parts['extension']);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: '.filesize($filePath));
readfile($filePath);
exit;
} else {
echo 'ERROR';
}
}
我用的是codeigniter, 回傳到ie是一個檔案的下載, 但是幫我做android的朋友說他沒法
接, 是他該改還是我改呢? 我有方法header可以直傳檔案麻?? 還是我的思路都錯了?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 183.178.187.30
※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1435632564.A.C07.html
→
06/30 11:40, , 1F
06/30 11:40, 1F
→
06/30 11:40, , 2F
06/30 11:40, 2F
→
07/01 10:12, , 3F
07/01 10:12, 3F
推
07/01 11:45, , 4F
07/01 11:45, 4F