RSS Forums RSS

Problem with dynamic paths

Thread Solved
Reply
Posts: 42
Reputation: marcmm is an unknown quantity at this point 
Solved Threads: 0
marcmm marcmm is offline Offline
Light Poster

Problem with dynamic paths

  #1  
Jan 12th, 2009
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?
AddThis Social Bookmark Button
Reply With Quote  
Posts: 579
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 121
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Problem with dynamic paths

  #2  
Jan 12th, 2009
You could use str_replace function to replace "//" with "/".
  1. $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';
  2. $uploadsDirectory = str_replace("//","/",$uploadsDirectory);
There are many other ways of fixing the problem. str_replace just seems the easiest to me.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote  
Posts: 42
Reputation: marcmm is an unknown quantity at this point 
Solved Threads: 0
marcmm marcmm is offline Offline
Light Poster

Re: Problem with dynamic paths

  #3  
Jan 16th, 2009
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...
Reply With Quote  
Posts: 11
Reputation: Yayo_SK is an unknown quantity at this point 
Solved Threads: 1
Yayo_SK Yayo_SK is offline Offline
Newbie Poster

Re: Problem with dynamic paths

  #4  
Jan 17th, 2009
Maybe this will work as well... ??????

  1. $uploadsDirectory = dirname(__FILE__) . '/uploaded_files/';
Last edited by peter_budo : Jan 18th, 2009 at 1:07 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the PHP Forum
Views: 420 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:14 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC