【发布时间】:2017-02-14 08:03:52
【问题描述】:
在强制下载前转换文件名。
我正在尝试能够在下载之前将存储文件名的文件名转换为原始文件名
所以当用户点击文件下载而不是显示时
post_1486965530_jeJNHKWXPMrwRpGBYxczIfTbaqhLnDVO.php
如下图所示
它只会将下载的文件重命名为
config.php
关于如何只在点击图片时更改下载的文件名。
public function downloads($id) {
$this->db->where('attachment_id', $id);
$query = $this->db->get('attachments');
if ($query->num_rows() == 0) {
return false;
}
$path = '';
$file = '';
foreach ($query->result_array() as $result) {
$path .= FCPATH . 'uploads/';
// This gives the stored file name
// This is folder 201702
// Looks like 201702/post_1486965530_jeJNHKWXPMrwRpGBYxczIfTbaqhLnDVO.php
$stored_file_name .= $result['attachment_name'];
// Out puts just example "config.php"
$original .= $result['file_name'];
}
force_download($path . $stored_file_name, NULL);
}
【问题讨论】:
标签: codeigniter