Page 1 of 1

Newbie Question (getting started)

Posted: Fri Sep 30, 2005 8:26 am
by Blyant
I'm just starting out with the possibilities of PHP, I've been reading around about Php for a couple of weeks and want to start a project and start learning more!

I'm a designer and want to create a simple portfolio, I want to load a bunch of .jpg files from the server into my flash front using php > xml >flash. So I will use "echo" in Php to make my Xml for flash, also I will use "getimagesize" to return width and height of my .jpgs.

Finally, my questions are:

How can I have Php list the names of my .jpg files in an Array? Is it possible? Do I need to use mysql(I'd rather not if possible)? Can you help or point me in the right direction to get help?

Cheers,
Blyant

Posted: Fri Sep 30, 2005 8:38 am
by Deemo
one thing you could do is to store all of the addresses of the file into a txt file and then use the file() function to read line by line, which is autmatically thrown into an array

If you dont wish to have a file, you could use some of the Directory Functions to get all the files in a directory, and then parse the strings (which would be the jpgs), and use your image functions to output the info into XML

Posted: Fri Sep 30, 2005 8:43 am
by Blyant
Thanks for the reply, I want the site to be dynamic so I can just upload photos and not have to add anything to the flash, xml or even a text file.

The second part of your answer looks promisng (while slightly confusing for me :D ). I'll get reading.

Thanks a lot!

Posted: Fri Sep 30, 2005 9:39 am
by Jenk

Code: Select all

<?php

$array = array();

if ($handle = opendir('/path/to/files/')) {

    while (($file = readdir($handle)) !== false) {

        if (substr($file, -3) == 'jpg') {

            $array[] = $file;

        }

    }

}

?>
Off the top of my head, that should work but may need tweaking :)