Problem with dynamic paths

Thread Solved

Join Date: Oct 2008
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

 
0
  #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:

  1. <?PHP
  2.  
  3. $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
  4.  
  5. // this echoes something like " /foldername/ " presumbing that the php file is set inside that folder in the root.
  6.  
  7. $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';
  8.  
  9. // this echoes something like this "C:/folder/subfolder//foldername/uploaded_files/"
  10.  
  11. ?>

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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Problem with dynamic paths

 
0
  #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 Quick reply to this message  
Join Date: Oct 2008
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

 
0
  #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 Quick reply to this message  
Join Date: Jan 2009
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

 
0
  #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 2: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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC