|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52466 PHP cannot see filenames with spaces
Submitted: 2010-07-28 10:27 UTC Modified: 2010-07-28 10:40 UTC
From: d dot reade at ReadesGroupServices dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.3.3 OS: CentOS 5.5
Private report: No CVE-ID: None
View Add Comment Developer Edit
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 - 20 = ?
Subscribe to this entry?

 [2010-07-28 10:27 UTC] d dot reade at ReadesGroupServices dot com
Using the scandir() method to fetch a list of filenames in a folder. Some filenames contain a space (via SSH this appears as "\ ", i.e. "test\ file.txt"). However PHP sees this file as "test_file.txt". This causes additional file operations such as file_exists() to return false.

Test script:
\\ path/to/folder/ contents:
\\ file.txt
\\ test\ file.txt

$scan = scandir('path/to/folder/');

foreach ($scan as $file)
    echo $file.'

Expected result:
test\ file.txt

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-28 10:33 UTC]
Works fine for me using latest SVN 5.3 build:

daniel@daniel-laptop:~/tmp$ ls -l
total 24
-rw-r--r-- 1 daniel daniel 0 2010-07-28 10:30 foo bar.txt
-rw-r--r-- 1 daniel daniel 0 2010-07-28 10:30 helloworld.txt
daniel@daniel-laptop:~/tmp$ php -r 'var_dump(scandir("."));'
array(4) {
  string(1) "."
  string(2) ".."
  string(11) "foo bar.txt"
  string(14) "helloworld.txt"
 [2010-07-28 10:40 UTC] d dot reade at ReadesGroupServices dot com
-Status: Open +Status: Closed
 [2010-07-28 10:40 UTC] d dot reade at ReadesGroupServices dot com
That's weird, it was doing it for me a second ago... and now it's not!! Sorry to waste your time, but thanks anyway.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Jan 28 03:03:45 2023 UTC