参数传送到视图问题

yyszj0911 2011-11-24 02:42:36
代码如下(传不到视图页) ,但是用预设的$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';}


...全文
147 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyszj0911 2011-11-24
  • 打赏
  • 举报
回复
传回js端就对了 但是死活php输不出来
yyszj0911 2011-11-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 heyli 的回复:]

在你的Action里面输出 $file 看下 不会是 dir 少跟个 /吧
[/Quote]
我用alert(result)}传回来显示的就是/var/www/test11.txt
yyszj0911 2011-11-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ohmygirl 的回复:]

值是怎么post过来的呢?
[/Quote]
$(function download(){	
$(".fileds").live("click",(function(){
var file_name = $(this).find(".name").text();
var dir = $("#bottom").text();

$("#download").click(function(){
$.post("download/index",{dir:dir,file_name:file_name},function(result){
location.href="http://dms.com/download"; }
//alert(result)}
)
})
}))
})
这么来的
heyli 2011-11-24
  • 打赏
  • 举报
回复
在你的Action里面输出 $file 看下 不会是 dir 少跟个 /吧
xuzuning 2011-11-24
  • 打赏
  • 举报
回复
预设的 $file="/var/www/test11.txt"; 显然是绝对路径,这自然没有问题

$file=$file_dir.$file_name;
如果也是绝对路径的话应该是没有问题的
如果是相对路径的话,那就要看是否正确了。至少要知道他相对于谁
ohmygirl 2011-11-24
  • 打赏
  • 举报
回复
值是怎么post过来的呢?

4,250

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧