Page 1 of 1
help me out: PHP picture gallery code
Posted: Thu Dec 10, 2009 9:42 pm
by hectorubie
hi guy,
i got this php code that suppose to take the pictures from inside a directory and make a picture gallery, but for some reason the picture come out in wit the [X] in the middle no picture displays. can anyone tell me why? can it be the folder permission? heres the php code i am using:
Code: Select all
<?php
$dir="directory path";
$path=getcwd().'/'.$dir;
$handle=opendir($path);
$i=1;
$handle=opendir($path);
while ($file=readdir($handle)) {
if (strpos($file, '.jpg')) {
$images = "<img src=\"p/$file\" alt=\"pic$i\" border=\"0\" height=\"90px\" width=\"120px\" hspace=\"5px\" />";
echo $images;
$i++;
}
}
?>
thx in advance
Re: help me out: PHP picture gallery code
Posted: Thu Dec 10, 2009 10:08 pm
by requinix
That tells the browser to look for the image in the p/ directory. If the image isn't there then it won't work.
If $dir is not "p" then you need to change the img's src to reflect that.
Re: help me out: PHP picture gallery code
Posted: Thu Dec 10, 2009 10:09 pm
by JAB Creations
Stick the images in to a database because then you'll have PHP in between the user and the image whereas if you can do user permissions with Apache there would be little point (besides password protection).
Then just do a while command to display each image. I haven't done it myself (yet) though I imagine it's actually a whole lot simpler then we both think.

Re: help me out: PHP picture gallery code
Posted: Thu Dec 10, 2009 10:27 pm
by hectorubie
JAB Creations wrote:Stick the images in to a database because then you'll have PHP in between the user and the image whereas if you can do user permissions with Apache there would be little point (besides password protection).
Then just do a while command to display each image. I haven't done it myself (yet) though I imagine it's actually a whole lot simpler then we both think.

hey thx for the fast respond, i dont know what u mean by stick the users pictures into the data base. let me explain how i have it set up.
when the members register a file is auto stored in members folder, n then when they upload pictures tha folder has an image file tha all there pictures are stored, i have a picture button, now when the user clicks that picture button i want a gallery of there pictures to come up.
Re: help me out: PHP picture gallery code
Posted: Thu Dec 10, 2009 11:05 pm
by hectorubie
tasairis wrote:
That tells the browser to look for the image in the p/ directory. If the image isn't there then it won't work.
If $dir is not "p" then you need to change the img's src to reflect that.
the $dir line goes into the right folder, its just that the when i look at my progress in my browser the picture comes out like a square wit an [x] n in the middle of the square i get the name of image thats inside tha folder, so the php code is working now why it doesnt display the pictures. thats drivin me nuts. heheh
thank u for ur response.
Re: help me out: PHP picture gallery code
Posted: Thu Dec 10, 2009 11:26 pm
by JAB Creations
When I first started learning MySQL I didn't want to put images in the database. However everything is part of a system and all systems have patterns, thus if there is any reason you do not want people to potentially see certain pictures you need to have them contained
behind something that you can apply permissions to where as with Apache the most complex "permissions" system you can work with is a universal user name and password.
So the question you should ask
before doing all the hard work is if there is any potential reason you wouldn't want someone to access any given picture that would be in the file system.
If there isn't continue as you are with your current question.
Otherwise you have to move files intentionally to a spot otherwise they are automatically deleted by PHP.
Uploaded files can be access via
$_FILES. Just look for an image upload tutorial, there are tons of them online.

Re: help me out: PHP picture gallery code
Posted: Thu Dec 10, 2009 11:34 pm
by hectorubie
JAB Creations wrote:When I first started learning MySQL I didn't want to put images in the database. However everything is part of a system and all systems have patterns, thus if there is any reason you do not want people to potentially see certain pictures you need to have them contained
behind something that you can apply permissions to where as with Apache the most complex "permissions" system you can work with is a universal user name and password.
So the question you should ask
before doing all the hard work is if there is any potential reason you wouldn't want someone to access any given picture that would be in the file system.
If there isn't continue as you are with your current question.
Otherwise you have to move files intentionally to a spot otherwise they are automatically deleted by PHP.
Uploaded files can be access via
$_FILES. Just look for an image upload tutorial, there are tons of them online.

thank u will do tha first thing in the mornig