General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 21st, 2003, 03:46 PM
paragon paragon is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 paragon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
about auto increment

I want to give uploaded files a certain name, but also have numbers on the end.

say I want to have them upload all files with the name "script" I dont want them to be overwritten so I want them to have a possible exstension of 4 numbers. like script0001 and so on. Would the auto increment and the default vaule work like that?

Reply With Quote
  #2  
Old July 23rd, 2003, 09:02 AM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Is there some certain reason you want them padded out with 0? You can't assign a default value to an auto_increment column, you can only set the starting value for the first number in the series. If you specified 0001, then your first auto increment value would be 1.

So, your table could look something like this:

+----+-----------+
| id | filename |
+----+-----------+
| 1 | image.jpg |
+----+-----------+

That's pretty simplified of course..

If you're storing the image binary data outside of your database (i recommend using a BLOB field), you could just write a function to check and see if the file exists in your target directory.
Example:

PHP Code:
function checkfile($file$append$dir)
{
  if (
is_file($dir.($append == '' : ((int)$append)).$file))
    
$append checkfile($file, ++$append$dir);
  return (
is_int($append) ? $append : ((int)$append));
}

// and you call it with:

$currentFileName $_FILES['file']['name'];
$targetDirectory '/home/sites/site1/web/uploads/';
$newFileName checkfile($currentFileName0$targetDirectory); 


Append is the value to tack onto the filename if that file already exists, and the function will keep going until it finds an available $filename.$append.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > about auto increment


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway