php page image links not working with MAMP - php

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.

Related

How should i save photos with php/apache?

My question is, where should i save photos that will be uploaded from the users?
my root dir for the server is
C:/apache
here i have the folder that contains the php files C:/apache/htdocs . I was wondering where should i save the files, i heard it will be better if i saved it somewhere else than the htdocs (folder that contains the php scripts), but here is the thing. If i save it directly to C:/apache then i can't access the photos. While saving it to a new folder in C:/apache/htdocs/photos would make the photos folder visible or accesible from the php pages. Is there a way i can save them somewhere else, like, let's say one folder up from the htdocs folder?
EDIT: the .htaccess seems like a good solution. Though i'm curious about this 1 thing:
I was thinking, is it possible to have directories something like this?
--->phpfiles
|--->index.php
|--->another.php
--->photos
|--->1.jpg
|--->etc.jpg
And still somehow link those photos to my php files? Like making the server only view the phpfiles folder for links and all of that (so i can go to localhost/index.php and not localhost/phpfiles/index.php ) ?
EDIT 2: My server root is C:/apache, while my Document Root is C:/apache/htdocs. in case of any misunderstanding, sorry
I would suggest putting the uploads in a folder like you suggested with C:/apache/htdocs/photos and place a .htaccess in that file that prevents direct access to the folder. That way the folder won't be visible and they can't access the images without the file name.
Another solution would be to upload the images on a third party server.

PHP/HTML image not being sourced when running XAMPP Server

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.

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.

Hard-coded image not displaying in wordpress footer

I finished a project using the Finesse Wordpress theme from Ixtendo several months ago and all was well. However, recently I've noticed that an image that is hard-coded in to footer.php no longer displays, instead all I see is the alt text.
I've also tried using the image as a background image to a div which doesn't work either.
Anyone know how to fix this?
Some further info in case it's useful. I had also hard-coded references to JS files in header.php which worked for a few months but then the theme stopped getting the links. I resolved this by installing a plugin called WP Headmaster which enqueues the JS in to the theme.
Thanks in advance for any help.
This will most likely be that the image location is specified relatively.
If you copied the location from the css file, the relative location will probably not have been changed.
You can verify this by right clicking on the image in google chrome/other capable browser, and selecting "open image in new tab". There you will see the absolute URL - which is probably incorrect.
A simple answer in the end.
We have a hosting account, e.g myhosting.com. The Wordpress site is loaded in to a directory called 'abc' within the main hosting account.
There is a domain name pointing at this directory, e.g. mydomain.com. The problem came from me using myhosting.com/abc/images/logo.jpg when I should have been using mydomain.com/images/logo.jpg
I obtained the correct URL via the media manager in Wordpress.

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