Jump to content
xisto Community
Sign in to follow this  
overture

A Php Gallery Commenting Script Question... i am working on a php script...

Recommended Posts

Hi all, i am working on a Gallery commenting script for myself and i got stuck at a part of it. I would like each new comment added to an image to be a number as the text file name like 1, 2, 3. everytime they add a comment the next file name is incremented (+1) and so on for example; if there was a text file names '1' then the next would be named '2'.I know how to create the file and the rest of it, but i would like to know how to do this. I should probably store the last file name somehow and then add 1 to it to create the next file but i do not know how.Thanksoverture.

Share this post


Link to post
Share on other sites

php has a built in ID function that generates an alphanumeric value based on microtime.

 

See Also This Topic

 

Otherwise, if you really want 1, 2, 3, 4, 5, 6, 7, ...

 

You'll need to create a count file with one line in it.

The line will just be the current number of files saved.

 

each time you save the comment file, you'll need to open the count fill, read the value, add 1 to the value, write the new value to the count fill and add the new value to the end of your filename.

 

This would create something like:

comment1.txt

comment2.txt

comment3.txt

 

A little php formating would allow for leading zeros.

Like this:

comment001.txt

comment002.txt

comment003.txt

...

comment025.txt

 

 

I suggest leading zeros because sorting generally requires this because the following computer sorting issue:

1

10

11

12

13

14

15

16

17

18

19

2

20

21

...

28

29

3

30

 

Leading zeros eliminates this proble up to the number of leading zeros.

Example:

0001 is good up to 9999 before sorting problems occur.

001 is good up to 999 ...

01 is good up to 99 ...

1 is good up to 9 ...

 

So you'll need to kind of guess how many files you'll have.

 

This is kind of basic explaination of what to do, if you need more specific information like code samples, let me know.

 

I always feel better when I figure it out on my own than just being told.

 

Happy Scripting, :D

vujsa

Share this post


Link to post
Share on other sites

Thankyou vujsa, that is what i this morning before i came on here to check. I wouldn't have thought about the leading 0 so it counts ok, thankyou for that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.