Upload images not showing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bjstyl2
Forum Newbie
Posts: 3
Joined: Mon May 25, 2009 10:57 pm

Upload images not showing

Post by bjstyl2 »

I have a folder where images get uploaded too but i want to create a php fileto show the array of images from this folder, its a simple web folder and all the images are jpg or gif. The images not not showing. Does anyone know what can cause this?

Also this is on a secure site and I get the warning about secure and unsecure information. Is there a way to fix the images so that this warning is not thrown.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Upload images not showing

Post by mikemike »

When you say the images are not showing, what do you mean? Are you just going to the folders location in your browser and hoping Apache will show you an index of all the files? If so this will only happen if it's set to do so in your Apache config. If you want to display all of the files in the directory I suggest using the glob function:

Code: Select all

<?php
foreach (glob("*") as $filename) {
    echo "<a href=\"$filename\">$filename</a> - size " . filesize($filename) . "<br />\n";
}
?>
 
The above will generate a list of all files in the current directory and give you their filesize in bytes. You can play with this to produce what you like.

With regards to the warnings about unsecured items. If you're on a secure socket layer (SSL - There is a https:// (note the 's') before the domain in the address bar) then you should only display items from a secure server. If you are displaying images in a format like the following...

Code: Select all

<img src="http://www.example.com/logo.jpg" alt="logo" />
...then you will generate a warning because the logo is not on an SSL.
Last edited by Benjamin on Tue May 26, 2009 1:33 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply