參數傳送到視圖問題
本帖最後由 yyszj0911 於 2011-11-24 14:43:05 編輯
代碼如下(傳不到視圖頁) ,但是用預設的$file="/var/www/test11.txt";的話就能夠傳的到 這是怎麼回事阿
controller:
function indexAction()
{
$file_dir = @$_POST["dir"]; //檔案路徑為目前的目錄
$file_name = @$_POST["file_name"]; //檔案名稱
$file=$file_dir.$file_name;
//$file="/var/www/test11.txt";
$this->view->downfile = $file;
echo $this->view->render('download/download.phtml');
}
view:
$file = $this->downfile;
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;
}
//$file = $this->downfile;
else{echo $file.'ssa';}
------解決方案--------------------
值是怎麼post過來的呢?
------解決方案--------------------
預設的 $file="/var/www/test11.txt"; 顯然是絕對路徑,這自然沒有問題
$file=$file_dir.$file_name;
如果也是絕對路徑的話應該是沒有問題的
如果是相對路徑的話,那就要看是否正確了。至少要知道他相對於誰