943,590 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 797
  • PHP RSS
Jan 12th, 2009
0

Problem with dynamic paths

Expand Post »
I'm trying to use some dynamic path names for an image upload page. In a tutorial they had something like this:

PHP Syntax (Toggle Plain Text)
  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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
marcmm is offline Offline
42 posts
since Oct 2008
Jan 12th, 2009
0

Re: Problem with dynamic paths

You could use str_replace function to replace "//" with "/".
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Jan 16th, 2009
0

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...
Reputation Points: 10
Solved Threads: 0
Light Poster
marcmm is offline Offline
42 posts
since Oct 2008
Jan 17th, 2009
0

Re: Problem with dynamic paths

Maybe this will work as well... ??????

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Yayo_SK is offline Offline
11 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: securing user page links
Next Thread in PHP Forum Timeline: PHP Ajax Search





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC