tags:

views:

460

answers:

2

I have created a program which allows me to upload images to my server. They are given a random file name when uploaded. I want to be able to download all the images from a folder on the server so I can display them in my application. The only example I have seen requires that I know the file name of the images which I don't. How could I download all the images in a given directory (and store the downloads in an NSArray)? If there is no native way to do it does anyone know a way that it could be done via calling a PHP script? (I use a PHP script which the iPhone calls to upload the images).

Thanks.

A: 

Hi,

you can call a php script that will return the url for all of your images.

something like

yoursite.com/image123.jpg;yoursite.com/image213.jpg;yoursite.com/imageabc.jpg

then you parse the result, split by ";" and get the array of urls which you need to download.

Adrian Pirvulescu
Could you show me some sample code? Sorry, but I don't really know PHP, just a very very basic understanding.
Gary
A: 

To list all images in a directory using PHP and return a JSON encoded string:

$path = '/full/path/to/images/';

// find all files with extension jpg, jpeg, png 
// note: will not descend into sub directorates
$files = glob("{$path}/{*.jpg,*.jpeg,*.png}", GLOB_BRACE);

// output to json
echo json_encode($files);
Glass Robot
Thanks a lot, very helpful.
Gary