PHP how to specify "back one directory level" in an url
Solution 1
Using what you stated above will work, so if you're in css and want to go to images (as an example) you would do the following:
require_once('../images/yourimg.png');
Solution 2
The require_once is simular to the require() statement but it checks wheter the file has been included already, and if it did, then it won't be included again.
Now for your question, if you have something like:
yoursiteurl/scripts/myscript.php
And you want that script to write a file to
yoursiteurl/images/sampleimage.jpg
Then you should reference the image destination to something like this:
copy('source/file/location/sampleimage.jpg', '../images/sampleimage.jpg')
NiqT
Hi! Donal is my name and I've been a Web Developer since 2009. My passion in life is making webpages for millions of people to enjoy and playing with the latest technologies is the best bit! Feel free to get in touch with me, but please, no spam..
Updated on August 27, 2020Comments
-
NiqT over 3 years
I have moved all of my files from being in the root (no folders, not very organised) so that they now reside within the following directory structure in my root folder:
css images js scripts index.html
... and this is fine. However, I have two or three php scripts which upload files (images) into the images folder above. This worked fine until I moved all of my files around and now I have been experimenting with things like "../" etc in order to link from the scripts directory, back one level, and then into the images directory.
Any help appreciated guys....