• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 838
  • Last Modified:

File Path Rules for PHP exec()

What are the 'rules' for specifying file paths for PHP's exec() function?  I am running PHP under Apache 2 in Windows XP.  I gather that the path separators need to be forward slashes.  I have not worked out what to do with spaces, though.  If there are any spaces in my file paths execution fails.  How can I escape spaces?  Also, are there any other Windows allowable characters that are likely to cause problems?

Mike

0
shacho
Asked:
shacho
  • 3
  • 3
2 Solutions
 
Michael701Commented:
you could use quotes around the file names in the exec

ie xp allows

copy "c:/temp/my file.txt" "d:/whatever.txt"

0
 
shachoAuthor Commented:
I tried that earlier, but it also fails for the same reason.  I get an error message saying the file cannot be executed and it displays the path all the way up to the first space.
0
 
Michael701Commented:
did the path that was displayed have a quote before the file name?

can you post an example?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
shachoAuthor Commented:
Problem solved.  The quotes need to be inside the text that is sent to the shell (I should have guessed that right off) so:

exec('C:/my folder/file.vbs')   //does NOT work (single quotes)
exec("C:/my folder/file.vbs")   //does NOT work (double quotes)
exec('"C:/my folder/file.vbs"')   //DOES work (double quotes INSIDE single quotes)

...which is probably what you meant by the first post, yes?

0
 
Michael701Commented:
yep, that's it
0
 
shachoAuthor Commented:
Great.  Thanks a lot for your help!

Mike

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now