Solved

PHP: OS Appropriate Directory Separator

Posted on 2011-03-16
2
269 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

20 Experts available now in Live!

Get 1:1 Help Now