| | |
Problem with dynamic paths
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 42
Reputation:
Solved Threads: 0
I'm trying to use some dynamic path names for an image upload page. In a tutorial they had something like this:
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?
PHP Syntax (Toggle Plain Text)
<?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?
You could use str_replace function to replace "//" with "/".
There are many other ways of fixing the problem. str_replace just seems the easiest to me.
php Syntax (Toggle Plain Text)
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/'; $uploadsDirectory = str_replace("//","/",$uploadsDirectory);
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
•
•
Join Date: Oct 2008
Posts: 42
Reputation:
Solved Threads: 0
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...
•
•
Join Date: Jan 2009
Posts: 11
Reputation:
Solved Threads: 1
Maybe this will work as well... ??????
php Syntax (Toggle Plain Text)
$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.
![]() |
Similar Threads
- Patching problem (C#)
- dynamic memory allocation in a struct (C)
- SATA HDD - problem after changing computer (Storage)
- I've got Trojan.Holax... is this bad? (Viruses, Spyware and other Nasties)
- not-a-virusadware (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: securing user page links
- Next Thread: PHP Ajax Search
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube





