hi,
I’m trying to make a form to download the dump file of database. I have successfully creating the file & locating it. But when I tried to download it, the file I’ve downloaded always be an empty file, it wasn’t the file I’ve created before. I’ve tried many methods but nothing works.
Here are some of methods I’ve tried…
//the first one
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
//the second one
$myfile = Yii::app()->file->set($file, true);
$myfile->permissions=777;
$myfile->download('file_backup_'.date('d-m-Y').'.txt', true);
//$myfile get the right file, because I get the right copy of file when I tried to copy it, below is the source to do copy
$mynewfile = $myfile->copy('test2.txt');
//I got just the right result when I open test2.txt
for the second one I used a cfile extensions and here is how to import it
Yii::import('application.extensions.file.CFile');
//the third one
Yii::app()->request->xSendFile($file, array(
'saveName' => 'RequestedFile.txt',
));
those are all methods I have tried, but none of them is working…
please help me solve this problem…
any help would be appreciate…
thank you…