Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.3

Request #7966 File_Find Stream Support
Submitted: 2006-06-23 00:43 UTC
From: ahayes at wcg dot net dot au Assigned: doconnor
Status: Closed Package: File_Find (version 1.2.2)
PHP Version: 5.1.4 OS: FC5
Roadmaps: (Not assigned)    
Comments Add Comment Add patch

Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem : 23 - 4 = ?

 [2006-06-23 00:43 UTC] ahayes at wcg dot net dot au (Alex Hayes)
Description: ------------ It would be really nice if File_Find had support for streams. It almost has basic support for streams, if we do not bother about context's, however it would not be hard to integrate context support. There are a few places that cause stream support to fail, mainly because of searching and replacing of DIRECTORY_SEPARATOR, which while I'm not exactly sure why it has been done I assume it is for security reasons. For example, lets assume we have a stream as follows: $files = File_Find::search("*.txt"); In its current form, File_Find replaces the directory to read as follows: ftp:/*.txt Notice the missing / in the stream path, causing the stream path to be invalid. By removing or changing these replacements as listed below basic stream support is enabled. It would not be too hard to also include context support, either in the constructor or within the search and glob functions. - Line 138 ( $directory = preg_replace("![\\\\/]+!", DIRECTORY_SEPARATOR, $directory); ) - Line 198/199 ( $path = str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path); ) Can these lines be replaced by something that does not destroy the stream part? Test script: --------------- $files = File_Find::search("file:///tmp"); Expected result: ---------------- Should return some files in the /tmp directory Actual result: -------------- PEAR Error is returned as follows: [pear_error: message="Cannot open directory" code=0 mode=callback callback=Controller::PEAR_Error_Handler prefix="" info=""]


 [2006-06-23 06:19 UTC] techtonik (anatoly techtonik)
I do not know what context, but fix for protocol separator seems to be easy. I'll look what could be done.
 [2006-06-23 07:18 UTC] ahayes at wcg dot net dot au
As in Stream Contexts ( Resource Contexts would be useful, say for instance as follows: =========8<============ $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en\r\n" . "Cookie: foo=bar\r\n" ) ); $context = stream_context_create($opts); /* Sends an http request to with additional headers shown above */ $fp = fopen('', 'r', false, $context); fpassthru($fp); fclose($fp); =========>8=========== So I imagine that it would not be to hard to pass thru a context resource into File_Find either in the constructor or as an optional param at the end of either File_Find::search and File_Find::glob
 [2006-06-30 14:47 UTC] techtonik (anatoly techtonik)
Funny enough, but I do not have privileges to upload the file to PEAR. It is ok here for developer to be without privileges to release, so while guys from above are coming up with a solution you may grab the files from here. Tell me if this "basic stream support" works. I left out contexts for the moment, because I do not have much experience with them. I do not want to break something if some additional context parameter to "opendir" and friends is just absent in PHP4.
 [2008-01-07 17:16 UTC] techtonik (anatoly techtonik)
Thank you for taking the time to report a problem with the package. Unfortunately you are not using a current version of the package -- the problem might already be fixed. Please download a new version from If you are able to reproduce the bug with one of the latest versions, please change the package version on this bug report to the version you tested and change the status back to "Open". Again, thank you for your continued support of PEAR.
 [2009-01-01 14:44 UTC] doconnor (Daniel O'Connor)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.