PHP/HTML image not being sourced when running XAMPP Server - php

When using XAMPP, I am loading a page (index.php) and am using MySQL to get the directory of an image I want to use. This is a snippet of the code block that does this:
<img src="<?php echo $resource['main_image'];?>">
I know that the php code is working because when I inspect element the page on localhost, I get
<img src="assets/images/defaults/default_pic.png">
This image exists in the folder but just doesn't seem to load when the server is run. When I inspect element and click on Sources, the image folder is not sourced, but the css and js folders are:
As you can see, the assets/images folder is not loaded. I can't seem to find any way to load this folder. I have tried other solutions to similar problems, such as giving an absolute path to the image, and yet other folders a sourced and not this image folder. I have tried looking for ways to source images in the head of the HTML, and those don't exist either.
In addition, it seems that if I explicitly state the image location and not use a MySQL Query to locate it, it loads fine. It is only when I query the location does the image not load.

A workaround that worked for me is to create a new directory for pictures outside of assets, in the working directory of the current file. It is not ideal, but it is a workaround for the issue.

Related

Images Won't Load But Path Is Right?

I've been working on my server for several days and I'm having major issues with server includes and images. I removed all of the PHP Includes but I would like to add them back. The other issue I'm having is with images. I've added the full path domain and all and it's still not loading the image. If you take the URL path of the image and place it in the browser, it works. I've cleared caches and cookies several times and still coming up with no solution.
http://cocrele.mobi
http://cocrele.mobi/welcome
The headers says that the image loading was forbidden:
"A 403 Forbidden error means that you do not have permission to view the requested file or resource. While sometimes the website owner does this intentionally, other times it is due to misconfigured permissions or an improper .htaccess file. "
You need to be aware that the images in CSS need to be relative to the path from style.css
So for instance, if you have the following folders:
index.php
img
img.jpg
css
style.css
If you are putting the image "img.jpg" in the "style.css", the path will be:
"../img/img.jpg"
While if you are putting images directly in your index.php the path will be:
"img/img.jpg"
Hope this helps.

PHP - Can't display images from parent directories

I am working on a program that involves displaying images stored in a server.
My working directory is
~/public_html/lab5/
The images are uploaded successfully to the following directory:
~/public_html/lab5/uploads/
Images ARE NOT displayed when I try to display the images using the path
~/public_html/lab5/uploads/image.jpg
but they are displayed normally using the following path
uploads/image.jpg
I'm just wondering, what is wrong with the relative-to-home path that I'm using?
Thanks in advance,
Rafi
It would be hard to say for sure without any idea what your server looks like, but I'm guessing based on the paths you've listed that ~/public_html/lab5 is your document root, in which case, the webserver doesn't know about anything except the contents of lab5 and its sub-directories.

This path for a picture doesn't work

I'm building graphs using pChart in PHP. The case is that I have my picture in the right folder, I know it because if I put that path in the browser I can see my picture, but in the template, it doesn't show up. Firebug shows "failed to load the given URI".
<img src="/home/user1/mysite/Admin/Template/mx_graphs/example13.png">
The picture has all the rw permissions given, and the folder.
You appear to be using a UNIX file path instead of a relative URI. Your web server is unlikely to be configured to have the DocumentRoot be / (and it would be very silly to do so).
Construct a URI relative either to the HTML document or to the DocumentRoot of your server.
The latter will probably be /Admin/Template/mx_graphs/example13.png
Remember the statement:
<img src="/home/user1/mysite/Admin/Template/mx_graphs/example13.png">
Will run on the client side, so if you run this on the very computer where the picture is stored, it should work fine, but if you try to open it from another computer it will not work.
Try to use relative path (http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/), and try to keep the website resources into the website root folder, so that even when you host the site the image be copied over and will still be accessible..

php page image links not working with MAMP

I'm running a php website locally using mamp. On the front page (i.e. index.php) there are a few broken image links that point to image files like '/images/logo.gif'. These were working on a version of the site hosted remotely.
In the actual main web folder I see a subfolder "resources" that contains the subfolder "images". I can't figure out whether the image links should know to look in the resources folder from other code or if the img src field in the html (from inspect element on the locally hosted version) should actually be reading 'resources/images/logo.gif'. I'm hesitant to just change the field in the code without knowing if it should be seeing the subfolder in resources.
EX.
-/site
-index.php
-/includes
-/resources
...
-/images
-logo.gif
...
-/css
etc....
I apologize for this novice question, but I just can't figure out the appropriate resources to find the right answer for this.
If your image links to "images/logo.gif" then your browser will look for the images folder in your root directory. The reason that you're getting broken image links is because you don't actually have an images folder there! You'll need to change everything to "resources/images/logo.gif".
Okay, so it looks like on the remote site there were actually two separate images folders, one at the root level, and one in the resources folder. That would explain my confusion.

Trouble locating images

I'm having trouble with missing images on my server.
I have been developing a site locally using MAMP for a while and now that I have uploaded it to my server the images cannot be found. Firebug tells me "Failed to load the given URL".
The file structure is the exact same as it was locally and the code is also the same.
The php file trying to load the images is in the site's root folder along with the folder "images".
Here is the file structure: images/models/dreadfinsl1.jpg
Here is the page: http://eoghanoloughlin.net/george/index.php
Can anyone help me? It seems like it would be just one of those stupid problems / simple answers but I'm relatively new to this don't have much experience. It was working fine when I was using MAMP.
Looks like your in the /george/ map on the server, and i assume locally u used www/
try /george/images/models/dreadfinsl1.jpg
else you will have to use full path http://eoghanoloughlin.net/george/images/models/dreadfinsl1.jpg
Try to access an image which is in your server with the help of web browser by specifying absolute path of the image....
Like http://eoghanoloughlin.net/images/models/dreadfinsl1.jpg
If you found any image on the browser, try to display the same image on your index page...
I think specifying the file path is being a problem in your application....

Categories