Home » HTML » HTML_Template_IT » Bug #9397
getFile() using fread() does not read whole file
Details
| Submitted | 2006-11-20 19:16 UTC |
|---|---|
| From | blair dot chesnut at duke dot edu |
| Assigned | dsp |
| Status | Bogus |
| Package | HTML_Template_IT |
| PHP Version | 5.1.2 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2006-11-20 19:16 UTC] blair dot chesnut at duke dot edu
Description:
------------
getFile() using fread() does not always get entire file, but sometimes only returns 8192 characters. Perhaps using fread() in a loop or get_file_contents() would resolve.
Test script:
---------------
<?php
require_once "HTML/Template/IT.php";
require_once "MDB2.php";
$template = new HTML_Template_IT('./test');
$dsn = "mssql://user:passwd@host/db";
$dbh = MDB2::factory($dsn);
$query = <<<EOQUERY
select *
from person
where lastname like ?
order by lastname, firstname
EOQUERY;
$sth = $dbh->prepare($query);
$res = $sth->execute('A%');
$results = $res->fetchRow();
$content = $template->getFile('templatefile.tpl');
print "Contents = " . strlen($content);
?>
Expected result:
----------------
Contents = 8207
Actual result:
--------------
Contents = 8192
[2006-11-20 19:38 UTC] dsp at php dot net
Can you give me additional information. Are you sure that the file is in your template root directory ?
I cannot reproduce the bug.
[2006-11-20 19:54 UTC] blair dot chesnut at duke dot edu
The problem apparently has to do with MDB2 and $sth->execute() using a placeholder. Works fine if the query parameter is hard-coded in the query. I read about similar problems using fread() after opening a "userspace stream".
[2006-11-20 21:26 UTC] blair dot chesnut at duke dot edu
You can chop out all the HTML_Template_IT code and add at the bottom:
$fp = fopen('./test/templatefile.tpl');
$content = fread($fp, filesize('./test/templatefile.tpl');
print "Contents = " . strlen($content);
Something in MDB2's execute() is causing fread()'s output to be limited to 8192 chars.
[2006-11-21 17:55 UTC] dsp at php dot net
Works perfectly for me, I created a template file with 9022 bytes and tried you script, but with mysql as I don't have access to a mssql server. But furthermore, if it's really a bug, it's not a HTML_Template_IT bug (Bogus for me).