Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-13-2004, 09:04 PM   #1
Registered: Mar 2004
Distribution: Mandriva 2010.0
Posts: 223

Rep: Reputation: 30
Handling filenames with spaces in PHP

I have some PHP pages that worked fine using a Windows based HTTP server (specifically OpenSA - Apache). I have since moved those pages to a Mandrake 9.2 system. The problem is that referencing filenames with imbedded spaces worked fine under Windows. However, in Unix those imbedded spaces cause errors. I can use quotes (") on the command line to access those filenames but that doesn't seem to work with the Mandrake version of PHP.

For example, what would be the corrrect syntax of:

if (file_exists($dirname."/".$filename.".txt")) {

if both of the strings in $dirname and $filename contain spaces?

I tried this to no avail:

if (file_exists("\"".$dirname."/".$filename.".txt"."\"")) {

Old 03-14-2004, 05:38 AM   #2
LQ Newbie
Registered: Nov 2003
Location: Socal
Distribution: Slackware, RedHat
Posts: 13

Rep: Reputation: 0
Did you try backslash in front of the space? For example...

$ cd "folder name"
$ cd folder\ name

Test it with the Mandrake version of php. If it works, just use str_replace or any similar functions to turn spaces into backslash spaces.
Old 03-14-2004, 01:03 PM   #3
Registered: Mar 2004
Distribution: Mandriva 2010.0
Posts: 223

Original Poster
Rep: Reputation: 30
No I didn't. Thanks for the suggestion.'ll give it a try.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
filenames with spaces antony.booth Programming 5 11-01-2005 04:49 AM
ls and filenames with spaces rose_bud4201 Programming 10 07-01-2005 08:28 AM
Spaces in filenames with mpg123 Boffy Linux - Software 3 04-26-2004 02:51 PM
filenames with spaces - explain t3___ Linux - Newbie 14 02-17-2004 06:13 PM
spaces in filenames ebone Linux - General 2 11-12-2001 11:56 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:21 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration