php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34829 file_exists() doesn't works for some files
Submitted: 2005-10-11 16:09 UTC Modified: 2005-10-13 00:47 UTC
From: kylnas at tiscali dot it Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.4.0 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kylnas at tiscali dot it
New email:
PHP Version: OS:

 

 [2005-10-11 16:09 UTC] kylnas at tiscali dot it
Description:
------------
PHP 4.3.11
file_exists() doesn't works for some file (created by gd libray), instead if i create manually a file in the SAME directory the function works.

Reproduce code:
---------------
$file = 'images/products/thumbnails/11940-77_jpg_thumb_80x68.jpg';	if (file_exists($file))
 echo 'yes';
else
 echo 'no';

Expected result:
----------------
YES.

The file does exist.

Actual result:
--------------
NO. If I create a file in the same directory (like "tmp.gif") and I use the same function i get a "Yes" result.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-11 16:11 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-10-12 22:19 UTC] kylnas at tiscali dot it
This is the code:
<?php
  $filename = '../images/products/thumbnails/101D0-86_jpg_thumb_75x75.jpg';
  echo 'File does exist but it is not found: ' . $filename . '<br />';
  echo 'If you copy the destination in a browser the file is visible<br />';
	if (file_exists($filename))
    echo 'YES<br />';
  else
    echo 'NO<br /><br />';

  $filename1 = '../images/products/thumbnails/tmp_gif';
  echo 'File (in the same directory)) does exist and it is found: ' . $filename1 . '<br />';
	if (file_exists('../images/products/thumbnails/tmp.gif'))
    echo 'YES<br />';
  else
    echo 'NO<br />';
?>

This is the online link:
http://81.174.30.88/tmp/tmp.php
 [2005-10-12 22:25 UTC] tony2001@php.net
"A reproduce script" means I need a script that I can copy/paste and reproduce the problem. Probably, with some additional actions (like creating a certain file etc.).

How do you suppose I should reproduce the problem with the script you've given? Obviously I don't have all your files here.
 [2005-10-12 22:46 UTC] tony2001@php.net
Please re-read my last post.
And don't paste huge scripts not related to the reproduce code if not asked for.
Basically what I need to reproduce it:
1) permissions on the files you can't find (I'm sure the filetype and the way you create them doesn't matter).
short version:
do `ls -l <file>` and paste the result here.

2) a *short* but *complete* reproduce case I can copy/paste and test it.
most likely I'll need to know your directory structure too (because you refuse to use absolute paths).
 [2005-10-12 23:12 UTC] kylnas at tiscali dot it
This is the ls -l tmp.gif:
-rw-r--r--  1 XXXXX psacln 0 Oct 12 22:16 tmp.gif

This is the ls -l 101D0-86_jpg_thumb_200x200.jpg
-rw-r--r--  1 apache  apache 19056 Oct 12 16:47 101D0-86_jpg_thumb_200x200.jpg

How can i give you a *short* but *complete* reproduce case?
The only thing i know is there are 2 files in the same directory, with the same permissions, that have 2 different behavoiur with the same function.
By the way, it doesn't matter my directory structure, cause I get the same error.
Anyway it's: '/var/www/vhosts/mydomain/httpdocs/"
I try:
<?php
	$tmp_img = imagecreatetruecolor($_GET['w'],$_GET['h']);
	$th_bg_color = imagecolorallocate($tmp_img, $r, $g, $b);
	imagefill($tmp_img, 0, 0, $th_bg_color);
	imagecolortransparent($tmp_img, $th_bg_color);
	$src = imagecreatefromjpeg($_GET['img']);
	imagecopyresampled($tmp_img, $src, 0, 0, 0, 0, $_GET['w'], $_GET['h'], $image[0], $image[1]);
?>
 [2005-10-12 23:27 UTC] tony2001@php.net
So they have totally different owners and groups.
Ok, at least this is a useful info.

Now please do the following:
<?
var_dump(file_exists("/var/www/vhosts/mydomain/httpdocs/images/products/thumbnails/101D0-86_jpg_thumb_75x75.jpg"));
?>
(or whatever the absolute path should be).

And tell me plz: safe_mode is On or Off?
And what's your error_reporting level along with display_errors ?
 [2005-10-12 23:39 UTC] kylnas at tiscali dot it
This is the message i obtain with your code:

bool(false)

I don't know how see your question about error, sorry...=((
 [2005-10-12 23:43 UTC] tony2001@php.net
Use phpinfo(); to see values of the options I was asking about.
 [2005-10-12 23:48 UTC] kylnas at tiscali dot it
error_reporting:
display_error=off
Local value=2039
Master value=2047
 [2005-10-12 23:55 UTC] tony2001@php.net
Turn display_errors On in the beginning of the code:
ini_set("display_errors", 1);
and see if there are any error messages.
Also, please tell me the value of "safe_mode" in phpinfo().
 [2005-10-13 00:25 UTC] kylnas at tiscali dot it
Where do i should see errors? in my first script?
 [2005-10-13 00:29 UTC] tony2001@php.net
Yes.
And I asked you about safe_mode.
 [2005-10-13 00:33 UTC] kylnas at tiscali dot it
Safe mode is on, and it seems there is no errors in my script. Simply the images aren't shown.
 [2005-10-13 00:44 UTC] tony2001@php.net
Read something about safe_mode.
No bug here - file_exists() and other filesystem funcs won't work with files that have different owner/group than script if safe_mode is On.
 [2005-10-13 00:47 UTC] kylnas at tiscali dot it
Ok, i got it.
Thanks a lot for your help.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 02:01:35 2024 UTC