Я пытаюсь загрузить файл в php. Я использовал как помощник загрузки codeigniter, так и файл чтения чистого php-кода. Я могу получить содержимое файла в сети браузера, но я не могу его загрузить.
Когда я попробовал функцию readfile в независимом файле php, он сработал.
Вот мой блок кода для файла dowload.
// codeigniter
$this->load->helper('download');
$data = file_get_contents(base_url("/images/logo.png"));
force_download($decodedFileInfo->fileName, $data);
// php readfile
$file = "./images/logo.png"; //. $decodedFileInfo->fileName;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}else{
var_dump("hst");die;
}
Спасибо..
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$name}");
header("Expires: 0");
header("Pragma: public");
Попробуйте сохранить имя файла и имя изображения в переменных и отобразить их на экране. Я тестировал эти функции отлично:
$this->load->dbutil();
//Calling a store procedure
$sp ="exec secondProc '5 Aug 2013'";
$query = $sqlsrvr->query($sp);//->result();
$jawad = $query->result_array();
//pass it to db utility function
$new_report = $this->dbutil->csv_from_result($query);
//Downloading the file
$this->load->helper('download');
force_download('csv_file.csv', $new_report);