Solved

PHP: OS Appropriate Directory Separator

Posted on 2011-03-16
2
267 Views
Last Modified: 2012-05-11
I want $SystemSlash to either be / or \ depending on the operating system.

How can I make $SystemSlash be the appropriate directory separator for the operating system used?
<?php

echo $SystemSlash . 'path' . $SystemSlash . 'to' . $SystemSlash . 'my/file.php';

?>

Open in new window

0
Comment
Question by:hankknight
2 Comments
 
LVL 2

Expert Comment

by:k_romych
ID: 35149656
if (strpos($_SERVER['DOCUMENT_ROOT'],'/')){$SystemSlash='/';}else{$SystemSlash='\\' ;}
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 35149811
Or even easier just use the constant name DIRECTORY_SEPARATOR:

<?php

echo DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'to' . DIRECTORY_SEPARATOR . 'my/file.php';

?>

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now