Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling filenames with spaces

Status
Not open for further replies.

awingnut

Programmer
Joined
Feb 24, 2003
Messages
759
Location
US
I'm running PHP with Apache on a Linux machine. I have a page that uses the PHP functions 'file_exists' and 'fdopen'. Some of the filenames contain spaces. How do I come up with the right syntax so that these functions work with this type of filename?

Among other attempts this is the latest:
Code:
   .
   . 
   .
elseif (file_exists("'".$dirname."/".$filename.".txt'")) {
		$fid=fopen("'".$dirname."/".$filename.".txt'","r");
   .
   .
   .
This appeears to be OS dependent (it works, without the extra quotes, under the Windows based OpenSA). Is there way to make it OS independent? TIA.
 
Linux system calls directly support filenames with spaces, without any extra trouble. Probably what you're thinking of is the BASH shell, which requires quoting of filenames to distinguish which arguments are which. I'm not sure how PHP handles this, but I'd be surprised if it needed any extra quotes or escaping. Try it!


I REALLY hope that helps.
Will
 
Thanks but that is where I started. The function 'file_exists' always fails if the path contains any spaces and seems to work fine when it does not. That is why I thought the problem was the same as in 'bash' and needed quotes. I don't know what to do at this point if even the quotes won't help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top