help me out: PHP picture gallery code

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
hectorubie
Forum Newbie
Posts: 10
Joined: Thu Oct 15, 2009 3:54 pm

help me out: PHP picture gallery code

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: help me out: PHP picture gallery code

Post by requinix »

Code: Select all

src=\"p/$file\"
That tells the browser to look for the image in the p/ directory. If the image isn't there then it won't work.

Code: Select all

$dir="directory path";
If $dir is not "p" then you need to change the img's src to reflect that.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: help me out: PHP picture gallery code

Post 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. :mrgreen:
hectorubie
Forum Newbie
Posts: 10
Joined: Thu Oct 15, 2009 3:54 pm

Re: help me out: PHP picture gallery code

Post 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. :mrgreen:

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.
hectorubie
Forum Newbie
Posts: 10
Joined: Thu Oct 15, 2009 3:54 pm

Re: help me out: PHP picture gallery code

Post by hectorubie »

tasairis wrote:

Code: Select all

src=\"p/$file\"
That tells the browser to look for the image in the p/ directory. If the image isn't there then it won't work.

Code: Select all

$dir="directory path";
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.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: help me out: PHP picture gallery code

Post 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. :google:
hectorubie
Forum Newbie
Posts: 10
Joined: Thu Oct 15, 2009 3:54 pm

Re: help me out: PHP picture gallery code

Post 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. :google:

thank u will do tha first thing in the mornig
Post Reply