php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54422 possibly a bug in file_exists() found
Submitted: 2011-03-30 14:19 UTC Modified: 2019-03-26 02:18 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: f dot roze dot n at hush dot ai Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.3.6 OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-03-30 14:19 UTC] f dot roze dot n at hush dot ai
Description:
------------
When using built-in function "file_exists" in 5.3.5 I encountered a trouble of locating one file, which had apostrophe in its' name.

$filename = "America's Army.png";
if ( file_exists($filename) ) echo "found it";
else echo "bug";

After backslashing the single quote ("America\'s Army.png"), I managed to get things working.
I considered this as bug since it has nothing o do with DB/HTML backslashing, and also took me a few hours to find out what the problem was.



Test script:
---------------
// To test, copy a single file called "America's Army.png" to the initial dir

$filename = "America's Army.png";
if ( file_exists($filename) ) echo "found it";
else echo "bug";

Expected result:
----------------
found it

Actual result:
--------------
bug

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-06 16:02 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2011-04-06 16:02 UTC] cataphract@php.net
Can't reproduce this. Are you sure the filename doesn't have a backslash?...

$ ls
file\' 1  file' 2
$ ~/php-t/bin/php
<?php
var_dump(file_exists("file\' 1"), file_exists("file' 2"));
bool(true)
bool(true)
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 [2019-03-26 00:52 UTC] christo at iagauctions dot com
I am having the same issue with file_exists:

I retrieve clients data from the DB, loop through it in while loopd, then check if they have an invoice:

$filename = "/invoices/invoice_".$auction_short_name."_".$lname."_".$member_id.".pdf";
if(file_exists($filename)) {
  $pdf_previw = "<a href=\"/invoices/invoice_".$auction_name."_".$member_name."_".$member_id.".pdf">INVOICE</a>";
} else {
  $pdf_previw = "";
}

This works as expected in all cases EXCEPT when there is an apostrophe in the clients name, IE $member_name=O'Rourke.

When i remove the "if(file_exists($filename))" check and just display:

$pdf_previw = "<a href=\"/invoices/invoice_".$auction_name."_".$member_name."_".$member_id.".pdf">INVOICE</a>";

it displays it correctly, and when clicked on displays the PDF file as expected. This to me indicates that the file_exists function is not executing properly.

PHP Version: 5.3.29
System:	Linux
 [2019-03-26 02:18 UTC] requinix@php.net
@christo: PHP 5.3 fell out of support years ago. Can you reproduce with PHP 7.1 or later?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 14:01:29 2024 UTC