PHP - Can't display images from parent directories - php

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.

Related

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.

Where is the folder that is created using php and mysql?

I'm learning PHP and MySQL but every time I read or watch tutorials and they write a code in PHP such as $sFolder="whatever/" to store data like images, videos, etc. They never explain where this folder is created or accessed.
For example, if I upload my code to a web server using these programming languages and I have $sFolder="whatever/"is the folder created and can be found on the web disk?
I'm trying to understand this so I know exactly what happens when I see a code like this.
The folder should be created in the current directory you're working in for example you're in the www folder it should be accessed via www/whatever
you can also use this code to get your current working directory
<?php
echo getcwd();
?>
and also a sidenote: php also uses a temporary folder when uploading images you could also check your php.ini file for this location if you ever need to
The folder is wherever you want it to be. Typically it's in the web root. So if your website is in e.g. C:\www\ then your folder is C:\www\whatever\
or on linux, something like /var/www/whatever/

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....

two sets of same php code with same version working differently on two different servers?

I made a class that converts a string of text into a png image and uploads on the server:
http://testing.mehhh.org/php/png.php (you can view php source on the page)
http://testing.mehhh.org/php/phg.php <-- shows php version
this one works great.
now I am trying to get this to work on a clients server
http://autoxplorer.com/~tameem/png.php This doesn't work!
http://autoxplorer.com/~tameem/php.php <-- also using same php version
what gives? I thought it's a permission thing.. but the png folder has full access.. and I tried a super simple uploading script and it runs and saves files to that folder. What is going on here?
You have just put online some PHP scripts that link to images. The link to the images actually is different.
http://testing.mehhh.org/php/png/4de9441d68cf8_1307132957.png
http://autoxplorer.com/~tameem/png/4de9424d41208_1307132493.png
While the first link returns actually an image, the second image link gives a 404 error. Looks like you have not configured your server properly to actually execute the PHP in the second case to return an image.

Categories