php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #6932 Filesize / File_exists and include_path
Submitted: 2000-09-29 02:08 UTC Modified: 2010-08-07 01:46 UTC
Votes:341
Avg. Score:4.7 ± 0.6
Reproduced:302 of 312 (96.8%)
Same Version:56 (18.5%)
Same OS:135 (44.7%)
From: richard dot heyes at heyes-computing dot net Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.0.2 OS: Any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: richard dot heyes at heyes-computing dot net
New email:
PHP Version: OS:

 

 [2000-09-29 02:08 UTC] richard dot heyes at heyes-computing dot net
Currently filesize and file_exists (possibly other, these are two I know of) don't appear to support an extra argument like fopen does to make use of the include_path. So the following code would fail if the file is in the include_path:

$file = fread($fp = fopen($filename, 'r', 1), filesize($filename));
fclose($fp);

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-12 15:25 UTC] sebastian@php.net
according to the docs: int fopen (string filename, string mode [, int
use_include_path])
 [2001-08-12 16:00 UTC] heyesr@php.net
That's nice. Doesn't solve the feature request though.
 [2001-08-12 16:32 UTC] heyesr@php.net
Maybe I should clarify, it was the filesize and file_exists function I was hoping would be updated to have an optional argument so they would check the include_path.
 [2002-06-04 09:13 UTC] mfischer@php.net
Any objection not to add this?
 [2005-06-30 19:15 UTC] sr at brightlight dot ch
I second this request.
Open since 5 years, since PHP5's autoload even more important 
and not even yet assigned... :-/
 [2006-02-24 22:38 UTC] arnold at bean-it dot nl
I third that!
And I would also like to see this argument for the function 'is_readable' and 'is_writable'.

Currently there is no clean way to check if a file can be included. Simply including a file which can't be opened causes a warning to be triggered. Suppressing include() with an @ is not advisable, since parse errors won't be displayed, but will cause the script to die, causing a blank screen. (Happy debugging, hope you're using ZendStudio).

The best solution I've come up with is:
if (($fp = @fopen($filename, 'r', 1)) and fclose($fp)) include_once($filename);

Anybody reading this bug PLEASE VOTE that this is important to you, because it doesn't look like anybody is willing to add this (simple) feature.
 [2006-03-08 16:41 UTC] ericjhollander at yahoo dot com
This is so obvious.  It should be there.  We should be able to do an easy test BEFORE calling include().
 [2006-04-05 09:30 UTC] rhoelvis-bell at yahoo dot com
I just think would be great to check before we get any kind of warning or whatever. And I also think would be of great importance to offer a clean code and service.
 [2006-11-08 22:37 UTC] ralph at smashlabs dot com
Why do you guys refuse to add some kind of functionality to the language that would allow people to test if a file is in the in the current include path (any of them) and where the file is located absolutely?  Seriously?

-ralph
 [2006-12-05 23:52 UTC] php at isnoop dot net
Another request for this feature.
file_exists(), is_readable(), is_writable(), and is_file() are begging for this.
 [2007-01-26 21:52 UTC] yarych at ua dot fm
This is really needed! Vote for this..
 [2007-02-18 16:36 UTC] zzarbi at free dot fr
Moreover with auload we can't "officialy" get an excepetion so add this parameter to this function is very important !!!
 [2008-06-08 17:44 UTC] pablo at rauzy dot name
This is another request for this feature. This has already been said : __autoload users need this feature !
 [2008-10-29 18:23 UTC] b_farrell60 at hotmail dot com
Ping!  This is still important (to me).
 [2009-03-06 16:46 UTC] paul at edunation dot co dot uk
This is one of those things that really should be added... Why am I still looping though the include paths?

$array = explode(PATH_SEPARATOR, get_include_path());

Come on, let's fix this in under 10 years!
 [2009-05-13 08:27 UTC] gw at spamspamspam dot fsnet dot co dot uk
Please add bzopen to the list of functions that really should support "use_include_path".  

Having to code full paths or loop through the include_path manually is amateurish for a language this evolved. :(
 [2010-08-07 01:46 UTC] johannes@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2010-08-07 01:46 UTC] johannes@php.net
.
 [2011-12-01 00:33 UTC] kevinpeno at gmail dot com
See dupe: https://bugs.php.net/bug.php?id=48173
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 16:01:27 2024 UTC