Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
Auto incrementing file name
Old 10-20-2009, 02:49 PM Auto incrementing file name
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
Hello,

I have a script that uploads photos to a directory. I am trying to rename the file on the fly with an incrementing value, i.e. 0001.jpg, 0002.jpg. I can not figure out for the life of me how to do it. Usually I would use rand(), but I need the file name to increase incrementally, preferably with the date prefixed. The code I have now just outputs a file named "11.png" every time. Can anyone point out what the problem is? Maybe a solution, also... Thanks!

PHP Code:
$file_name=date('m-d-y');
$file_int=$file_name 1;
$image_name=$file_int.'.'.$extension;
$newname="images/".$image_name
werm82 is offline
View Public Profile
 
 
Register now for full access!
Old 10-20-2009, 03:07 PM Re: Auto incrementing file name
Average Talker

Posts: 24
Location: Germany
Trades: 0
Basically, your code could look like this:
PHP Code:
$index=yourFunctionToGetTheCurrentValue();

$file_name=date('m-d-y');
$file_int=$file_name.'_'.$index;
$image_name=$file_int.'.'.$extension;
$newname="images/".$image_name;

yourFunctionToWriteDownTheNewValue($index+1); 
You could store the current value in an extern file for example. yourFunctionToGetTheCurrentValue() would be a function that opens this extern file and reads this value.
__________________

Please login or register to view this content. Registration is FREE
- Register Now and Share Your Thoughts to Create Innovation and Wisdom


Please login or register to view this content. Registration is FREE
- Psychology, Philosophy and Self Development


Please login or register to view this content. Registration is FREE
- Read About All Those Things That Bug Me
Trey Walter is offline
View Public Profile Visit Trey Walter's homepage!
 
Old 10-20-2009, 03:16 PM Re: Auto incrementing file name
NullPointer's Avatar
Will Code for Food

Posts: 2,781
Name: Matt
Location: Irvine, CA
Trades: 0
Date returns a string, not a number.
PHP Code:
$file_int=$file_name 1//invalid 
The best approach would probably be to store the current count somewhere and increment it every time you add an image:
PHP Code:
$count//the current image count
$filename 'images/' date('m-d-y') . $count '.' .$extension;
$count++;
//store the new value of count 
You'll have to figure out how to store $count.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
View Public Profile Visit NullPointer's homepage!
 
Old 10-21-2009, 12:31 PM Re: Auto incrementing file name
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
http://www.php.net/glob
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
View Public Profile Visit mtishetsky's homepage!
 
Old 10-21-2009, 06:43 PM Re: Auto incrementing file name
Junior Talker

Posts: 1
Trades: 0
Hello,
The solution that Trey Walter gived to you is a good one. The rest of the problem with the yourFunctionToGetTheCurrentValue() can be found here:
http://www.alfafiles.com/php/auto-in...thout-mysql/45

In order for this to work you will have either to put the date after the index number or to format the date in an alphabetical incrementing way ( y/m/d ).
Mipet is offline
View Public Profile
 
Closed Thread     « Reply to Auto incrementing file name
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33226 seconds with 12 queries