Newbie Question (getting started)

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
Blyant
Forum Newbie
Posts: 12
Joined: Fri Sep 30, 2005 8:14 am

Newbie Question (getting started)

Post 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
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post 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
Blyant
Forum Newbie
Posts: 12
Joined: Fri Sep 30, 2005 8:14 am

Post 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!
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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 :)
Post Reply