Page 1 of 1
Writing to txt files...
Posted: Thu Oct 08, 2009 4:05 pm
by MiniMonty
Hi all,
I'm running a site with a Flash front end. The Flash reads arrays of images and displays them.
So far so simple.
The arrays in txt files and are updated dynamically by php and when a user uploads a new image the file is appended
with the path to that image. All is well.
Now I need to improve the system in two ways.
First, I need the most recently uploaded images to appear first in the array. So is there a way to append the
contents of the .txt file at a certain point ?
i.e. after the initial variable "allpics=" which is the very first thing in the .txt file.
Also, is there a way of counting the number of occurrences of the string ",jpg" in the txt file ?
If so I can then append the end of the file with a total number of images variable and the gallery will loop.
Best wishes
Monty
Re: Writing to txt files...
Posted: Thu Oct 08, 2009 4:14 pm
by Mirge
Post an example of your .txt file that you're trying to parse.
Re: Writing to txt files...
Posted: Thu Oct 08, 2009 4:34 pm
by MiniMonty
Dead simple stuff:
A user uploads a picture and chooses a gallery to display it in (portraits / landscapes etc) via a drop down menu. The script uploads the picture to their own images folder, then references the path
to that image and writes the path to a txt file which sits in the dir of whichever gallery they have
chosen to display it in. The flash front end just reads the txt file and pulls the images
from wherever they are.
So each dir (portraits / landscapes etc.,) will include just the txt file which will look like this:
allpics=members/1/images/13.jpg,members/291/images/14.jpg,members/6/images/15.jpg, etc etc.,
members = a directory
6 = the member's number in date order as they joined
images = the member's own images folder
14.jpg = the 14th image they have uploaded
What I want to do instead of appending the txt file at the end is insert the new data (the image path) after the variable "allpics=" that way the newest upload will always display first.
Also, if I could count the number of times the string ".jpg" occurs in the txt file I could set a variable
for Flash of "&totalimgs=" and when it reached that number it would read the array from scratch and
therefore loop the gallery.
Any ideas ?
Best wishes
Monty
Re: Writing to txt files...
Posted: Fri Oct 09, 2009 10:29 am
by MiniMonty
Anyone got an idea about this ..... ?
You can see the flash gallery in action here:
http://www.shutterbugclub.com/gallery.php
And you can see the problem if you click through portraits or landscapes that after a while
(when it's shown all the pictures once) flash just carries on with a blank screen.
Best wishes
Monty
Re: Writing to txt files...
Posted: Fri Oct 09, 2009 3:52 pm
by requinix
MiniMonty wrote:Hi all,
I'm using the code below to append a simple array held in a txt file.
The script (at the end of an upload process) appends the file with a path to an image just uploaded by a user.
It works just fine.
What do I need to add to have the script count the elements in the newly appended array ?
The array in the text file is very simple and looks like this:
allpics=members/21/images/24.jpg,members/9/images/336.jpg,members/45/images/3.jpg,members/567/images/2.jpg,
Best wishes
Monty
Code: Select all
$myFile = "images/gallery/".$_POST ['gowhere']. "/gallarray.txt";
$fh = fopen($myFile, 'a+') or die("can't open file");
$stringData = "members/".$id."/images/".$newname .",";
fwrite($fh, $stringData);
fclose($fh);
You could
count the number of commas.
While you're at it you might as well
read in the entire file, count the commas (and add one), append the new path, and
write it all back.
Re: Writing to txt files...
Posted: Fri Oct 09, 2009 4:05 pm
by MiniMonty
I though of counting the commas, simple but effective - and I've been trying to use count but as
a big fat newb I could only get it to count the contents of the directory - not the file.
Any advice?
Best wishes
Monty