Reputation: 3615
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....
Upvotes: 6
Views: 51844
Reputation: 8711
As other answer notes, from current directory up a level and then back down to images can be done via a path like "../images/yourimg.png"
.
An alternative to that method is using an HTML <base>
Tag pointed at the parent directory, after which you would use paths like"images/yourimg.png"
to reference in images, or "js/some.js"
in js, etc.
Upvotes: 0
Reputation: 624
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')
Upvotes: 1
Reputation: 1489
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');
Upvotes: 14