
July 23rd, 2003, 09:02 AM
|
|
Contributing User
|
|
Join Date: Aug 2002
Posts: 232
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 == 0 ? '' : ((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($currentFileName, 0, $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.
|