NYCPHP Meetup

NYPHP.org

[nycphp-talk] opening files

ali mohammad ali at vpproperty.com
Fri Oct 26 02:04:46 EDT 2007


Putting image paths in a database would only work if you know beforehand
the path and name of all the images you want displayed (not to mention
the unreasonable overhead of updating that database for additional
images added or existing image files renamed later on). What you would
want, if David's assumption is correct, is to automatically read the
names of all image files contained in a given path location at the time
of script execution , and then loop through each of the names and
display the appropriate html img tag for each of these images.

 

IMHO, you could adopt for a simpler approach by using the concept of
<google_for_more_info>directory browsing in php</google_for_more_info>.
The pseudo code of one possible way (among several others) would be
something like this (hopefully assuming you are not stuck in a chrooted
web jail). 

 

function displayallimages($imagepathlocation) {

    $listoffiles = system("ls " . $imagepathlocation); 

     //filter $listoffiles to contain an array list of only valid image
files based on allowable image file extensions

    foreach($listoffiles as $imgfile) 

        echo '<img src='.$imgepathlocation.'/'.$imgfile.'/>'; //make
sure the image path here is relative to the document root of the web
server

}

 

Or at least I think that is one way to do it. 

 

________________________________

From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of Susan Shemin
Sent: Thursday, October 25, 2007 7:26 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] opening files

 

Just adding on David's answer -- put the name/path of the image in a
variable in your database.  I've done it because the name of the image
matches the name of the record entry so it's easy to locate the correct
image to display through a query.  Let's say the business is Susan so my
logo for the business is named susan.jpg which I can easily locate in a
query.

 

susan

----- Original Message ----
From: David Krings <ramons at gmx.net>
To: NYPHP Talk <talk at lists.nyphp.org>
Sent: Thursday, October 25, 2007 3:37:01 PM
Subject: Re: [nycphp-talk] opening files

selyah wrote:
> Hello Folks:
> I am still relatively new with php and am enjoying it very much.  I am

> creating a html script to show images  on a page.  instead of creating
a 
> source image for  all of the images, i would like to incorporate a php

> script that would "go" to the file location where all of the images
are 
> and display them.  I wrote a script but it does not work.  Any help or

> ideas ?  thanks
> new guy

You'd need to provide some code samples for us to give you some advice.
Also, 
what do you consider the difference between "creating a source image"
and "go 
to the location where all of the images are and display them"? I'd
establish a 
place where all images are (as appears to be given in your case), then
write a 
script that creates pages with <img> tags that point to the image in the

specific location.

I created and still work on a very similar system with a database
backend that 
allows for quite complex searches and a bunch of other stuff.

Basically, you need to tell us what you did so that we can tell you what
you 
did wrong.

David
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com <http://www.nyphpcon.com/> 

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20071026/b184e217/attachment.html>


More information about the talk mailing list