php - Download File in Yii -
i trying write script in yii downloading files server.
the files located in webroot of yii project,
but got every time file not exist error, see wrong:
public function actiondownload($id) { $audio = audio::model()->findbypk($id); $file = yii::getpathofalias('webroot') . $audio->path; if (file_exists($file)) { header('cache-control: must-revalidate, post-check=0, pre-check=0'); header('content-description: file transfer'); header('content-type: application/octet-stream'); header('content-disposition: attachment; filename=' . $audio->path); header('content-length: ' . filesize($audio->path)); $audio->downloaded = $audio->downloaded + 1; $audio->save(); }else{ echo "file not exist: ".$file; } exit; }
error got is:
file not exist: /var/www/vhosts/ikhwanbiz.org/httpdocs/userfiles/reklames/media/deneme/sen%20dep%20olmisem.mp3
thanks
regards
bili
bili, works me , seem fine on browsers.
$filename = 'your_file_name.csv'; header('content-disposition: attachment; charset=utf-8; filename="'.$filename.'"'); $utf8_content = mb_convert_encoding($content, "sjis", "utf-8"); echo $utf8_content; yii::app()->end(); return;
hope helps, luck!
php yii
No comments:
Post a Comment