Image problems using include

Asked

Viewed 50 times

0

I am developing a website and after developing most of the files, I decided to organize them in their respective folders.

localhost/hostname/ -- root directory
localhost/hostname/includes/ -- directory where navs, administrative bars, footers are located
localhost/filename/uploads/ -- folder containing image uploads
localhost/hostname/includes/adminbar.php -- this administrative bar, has in its code, a php snippet with echo of a url saved in the database.
localhost/hostname/restricted/-- folder where files for restricted access users are located
localhost/hostname/restricted/start.php -- home page for logged in users.

Well, the error I am facing is as follows, once I put the files in the new folders, the images stopped appearing and when I go to check their url, the url I get is as follows:

restricted/uploads/imgs/users/4153eb08425b193e0092b9cbeb509d62.jpg

Since what you are is:

/uploads/imgs/users/4153eb08425b193e0092b9cbeb509d62.jpg

That is, the file "pulls" the current folder path, this error occurs only when the files are in the subfolders, when all the files were in the root folder, no error appeared.

  • The "uploads" folder is inside the "restricted" folder or at the root?!

  • is inside the root @Davidsam, meaning there is a folder "above"

  • If a folder is up, then the image src should be src=".. /uploads/imgs/users/4153eb08425b193e0092b9cbeb509d62.jpg". With ".. /" before.

  • Yes yes, I understand! however, this would not solve my problem as the file that displays this image is a file that is in include folder, and it should supposedly work in any system folder, understand the problem? I could solve the problem by putting ".. /" but it would only work in this specific folder

  • @Davidsam This image is inside a file in the /include folder. Imagine that I create another subfolder for the /restricted folder. and do the file include with the image, the ".. /" would not be enough, it would have to be two ".. /.. /" that is, I need a solution to solve this under any circumstances

  • In this case I think q vc should include in the image src a path via server script: src="<? php path_fisico_do_server ? >/uploads/imgs/users/4153eb08425b193e0092b9cbeb509d62. jpg"

  • I think I get it. You have to load the image with a single path no matter which folder the page is in. In my previous comment it would not work to take the physical path of the server.

  • I think I would make comparisons like: if the page is in a subfolder X, then ".. /" or if it is in a Y, then "../../"

  • @Davidsam I solved the problem with absolute path, in the file that is in the include/ folder.. I wrote : echo "https://localhost/namesdite/". $url_da_image; and Solved. Thank you so much for your help!

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.