|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-12-12 13:26 UTC] erwan dot oger35 at gmail dot com
Description: ------------ --- From manual page: http://www.php.net/httpresponse.setstream --- When a resource is created by a streamWrapper::stream_open() method, it can't be "read" by the HttpResponse::setStream() method. However I can read it with fread() function. Test script: --------------- Expected result: ---------------- When I want to display a file contents, I expect to see it. Actual result: -------------- Actually, I see nothing (a white page on a browser) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
Hello, Sorry to be late ! After severals tests : IT'S NOT A BUG => the problem was between the chair and the keybord !!! It was a bad stram_stat function's implementation =S You can try the following code if you want ! (sorry for the size of this example but it's very difficult to do better) Bye ! <?php stream_wrapper_register('foobar', 'MyStreamWrapper'); $handle = fopen('foobar://fguyefhnizenhrczego', 'r'); HttpResponse::setCache(true); HttpResponse::setCacheControl('public', 3600, false); HttpResponse::setContentType('text/plain'); HttpResponse::setStream($handle); HttpResponse::send(); die; class MyStreamWrapper { private $path; private $mode; private $length; private $position; public function stream_stat () { $ino = mt_rand(0, 9999999999); $mode = 100755; $nlink = 1; $rdev = 0; $size = $this->length; $atime = time(); $mtime = time()-(60*60*24); $blksize = -1; $blocks = -1; $res = array( 0 => 0, 'dev' => 0, 1 => $ino, 'ino' => $ino, 2 => $mode, 'mode' => $mode, 3 => $nlink, 'nlink' => $nlink, 4 => 0, 'uid' => 0, 5 => 0, 'gid' => 0, 6 => $rdev, 'rdev' => $rdev, 7 => $size, 'size' => $size, 8 => $atime, 'atime' => $atime, 9 => $mtime, 'mtime' => $mtime, 10 => $mtime, 'ctime' => $mtime, 11 => $blksize, 'blksize' => $blksize, 12 => $blocks, 'blocks' => $blocks ); return $res; } public function stream_open ( $path, $mode ) { $this->path = $path; $this->mode = $mode; $this->length = 1024*1024; // 32Mb $this->stream_seek(0); return true; } public function stream_seek ( $offset, $whence = SEEK_SET ) { switch ( $whence ) { case SEEK_SET : $this->position = $offset; break; case SEEK_CUR : $this->position += $offset; break; case SEEK_END : $this->position = $this->length + $offset; break; default : return false; break; } // si le curseur dépasse la taille du fichier, on le remet à la fin du fichier if ( $this->stream_eof() ) $this->position = $this->length; /* ... */ return true; } public function stream_read ( $count ) { if ( $this->mode != 'r' ) return false; // initialisation de la variable de retour $data = ''; while ( !$this->stream_eof() && ($count > 0) ) { $tempData = randString(mt_rand(1, $count)); $tempData_size = strlen($tempData); $data .= $tempData; $count -= $tempData_size; $this->stream_seek($tempData_size, SEEK_CUR); } return $data; } public function stream_tell () { return $this->position; } public function stream_eof () { return $this->position >= $this->length; } public function stream_close () { return true; } } function randString ( $length, $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789' ) { $str = ''; $count = strlen($charset); while ($length--) { $str .= $charset[mt_rand(0, $count-1)]; } return $str; }