Click to See Complete Forum and Search --> : changing / into \ ;)
bunker
06-11-2005, 10:05 PM
Simple question.. i have this code:
$uploaddir = get_setting('absolutepath').'/'.$imgdir.'/'.$filename;
And this only works on Linux/Unix.. How could I change the code so the / is a \ and it works on Windows?
Thx
bubblenut
06-12-2005, 12:17 AM
DIRECTORY_SEPARATOR constant instead of the '/' would make the code more portable. To make the change accross many files I'd use a unix shell script.
for file in $(ls *.php)
do
sed "s/'\/'/DIRECTORY_SEPERATOR/g" $file > tmp;
mv tmp $file;
done
bradgrafelman
06-12-2005, 05:19 AM
Heh.. nice unix shell script. Probably only works in unix though, and we're talking about a Windows issue! :p
bunker - why not just reverse the slashes?
$uploaddir = get_setting('absolutepath').'\'.$imgdir.'\'.$filename;
bubblenut
06-12-2005, 10:37 AM
a. Granted, but there's always cygwin. Also, the concept is what's important, this could be done just as easily with a php script.
b. Your sollution would still mean having to go through all the files which use slash as the directory seperator and replacing them with a backslash. Also, that leaves you with exactly the same issue should you ever what to port the code back to unix. If you use the DIRECTORY_SEPERATOR constant you never have to worry about the issue again.
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.