DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Problem with dynamic paths (http://www.daniweb.com/forums/thread167870.html)

marcmm Jan 12th, 2009 10:10 am
Problem with dynamic paths
 
I'm trying to use some dynamic path names for an image upload page. In a tutorial they had something like this:

<?PHP

$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

// this echoes something like " /foldername/ " presumbing that the php file is set inside that folder in the root.

$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';

// this echoes something like this "C:/folder/subfolder//foldername/uploaded_files/"

?>

basicly when you put the two strings togheter to create the path, in this case for a temporary directory to store uploaded files, each string has an "/" at the end and beginning... so when you link them you get "...subfolder//foldername..."

Is there any way to force any of the above commands not to display one of the "/" or to somehow eliminate it in order for the path to be valid?

buddylee17 Jan 12th, 2009 3:59 pm
Re: Problem with dynamic paths
 
You could use str_replace function to replace "//" with "/".
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/'; 
$uploadsDirectory = str_replace("//","/",$uploadsDirectory);
There are many other ways of fixing the problem. str_replace just seems the easiest to me.

marcmm Jan 16th, 2009 3:01 pm
Re: Problem with dynamic paths
 
thank you for the suggestion... but it turns out that it dosen't need it... despite the fact that echoing the patch and copy pasting that in a browser dosen't work... it seems that php is somehow able to interpret it properly and the code works even with "//" in it... I have no idea how but oh well...

Yayo_SK Jan 17th, 2009 5:50 pm
Re: Problem with dynamic paths
 
Maybe this will work as well... ??????

$uploadsDirectory = dirname(__FILE__) . '/uploaded_files/';


All times are GMT -4. The time now is 2:21 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC