小编jso*_*onx的帖子

php,文件下载

我正在使用简单的文件下载脚本:

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;
}
Run Code Online (Sandbox Code Playgroud)

它正在我的本地服务器上工作高达200mb.

当我在我的网站上尝试此代码时,它下载173KB而不是200MB文件.

我检查了一切,写了一些自定义代码(使用ob函数和fread而不是readfile)但无法下载大文件.

谢谢您的回答.

  • 我使用的是Apache 2.2,PHP 5.3
  • 处理大文件的所有PHP设置都可以.(执行时间,内存限制,......

php header file download

16
推荐指数
1
解决办法
3万
查看次数

Php继承

我正在使用PHP 5.3稳定版本,有时我会遇到非常不一致的行为.据我所知,在继承中,超类中的所有属性和方法(私有,公共和受保护)都是传递子类.

class Foo
{
    private $_name = "foo";
}
class Bar extends Foo
{
    public function getName()
    {
        return $this->_name;
    }
}
$o = new Bar();
echo $o->getName();

//Notice: Undefined property: Bar::$_name in ...\test.php on line 11
Run Code Online (Sandbox Code Playgroud)

但是当Foo :: $ _ name属性定义为"public"时,它不会给出错误.PHP有自己的OO规则???

谢谢

编辑:现在一切都很清楚了.实际上我在思考"继承"时创建了一个新类,并且继承了独立于其祖先的所有成员.我不知道"访问"规则和继承规则是一样的.

编辑 根据您的评论,此代码段应该给出错误.但它正在发挥作用.

class Foo
{
    private $bar = "baz";

    public function getBar()
    {
        return $this->bar;
    }
}

class Bar extends Foo
{}

$o = new Bar;
echo $o->getBar();      //baz
Run Code Online (Sandbox Code Playgroud)

php oop inheritance

6
推荐指数
1
解决办法
2517
查看次数

为什么我的JavaScript函数不能访问我的其他.js文件中定义的全局范围函数/变量?

我写了一个这样的脚本:

NS.load = function(src) {
    var script = document.createElement("script").setAttribute("src", src);
    document.getElementsByTagName("head")[0].appendChild(script);
}
Run Code Online (Sandbox Code Playgroud)

它加载文件,但我无法到达其他文件中的功能和变量.

//js/main.js
var qux = {name: "name"};
NS.load("js/foo.js");

//js/foo.js
alert(qux.name); //undefined variable
Run Code Online (Sandbox Code Playgroud)

但如果我像这样定义qux:

window.qux = {name: "name"};
Run Code Online (Sandbox Code Playgroud)

我可以在其他模块中访问qux变量.据我所知,所有全局变量都已经是window对象的成员.那么为什么我必须定义这样的变量.你能提供另一种方法吗?

谢谢.

javascript

2
推荐指数
1
解决办法
1万
查看次数

Joomla用户登录检查

首先,我不是一个joomla开发人员.我的朋友有一个用joomla 1.5创建的网站.在webroot中有一些joomla文件.我在webroot"mydirectory"中创建了一个目录,我在这个目录中有一个索引文件.我尝试在此页面中访问joomla的用户信息,我抓住用户对象,但它不起作用.

 //i included joomla core  files
 $user =& JFactory::getUser();

 if ($user->get('guest')) {
     echo 'guest';
 } else {
 echo 'not guest';
 }
Run Code Online (Sandbox Code Playgroud)

当我登录我的帐户时,它再次显示"来宾".

另外,我在Joomla的会话课中找不到任何东西.

$session =& JFactory::getSession();
Run Code Online (Sandbox Code Playgroud)

谢谢

joomla login joomla1.5

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×2

download ×1

file ×1

header ×1

inheritance ×1

javascript ×1

joomla ×1

joomla1.5 ×1

login ×1

oop ×1