My guess is that 1,000 files is not too many files to store in one directory. OK, here is some code (untested) that illustrates what I was thinking...
Lets say your have a database table:
CREATE TABLE Article(
art_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
art_text TEXT
);
PHP Code:
<?php
/* Assumptions:
1) You have opened a connection to mysql and selected the database.
2) $articleText holds the text POST by the user
3) In your form you created an array of file upload input boxes like:
<input name="userfile[]" type="file">
So now you script will have received the folowing variables via POST:
$userfile[] - an array of the temp filenames on your server
$userfile_name[] - an array of the filenames as they were named
on your user's computer.
$userfile_size[]
$userfile_type[]
4) It is assumed that your user will have embedded [pic="xyz.gif"] type
tags and provided the correct file names to match the files they actually
uploaded through the form. You could create some validation code to validate
this if you wanted to.
5) It is assumed that you have used strip_tags() and add_slashes(), etc,
to user data to make it friendly.
*/
// insert $articleText into a new row in table Article for the new article
$sql = "INSERT INTO Article SET art_text='$articleText'";
$result = mysql_query($sql);
// grab the value of art_id for this new row
$artId = mysql_insert_id();
// now loop through the uploaded files and:
// - create a string as the file name under which they are to be saved locally.
// - then copy the file into its location using the file name
for ($i = 0; $i < count($userfile); i++) {
$newFileName = $artId . '_' . $userfile_name[$i];
copy($userfile[$i], "/path/to/image/dir/$newFileName");
}
?>
As an example, if the user uploaded files "foo.jpg", "bar.jpg", and the value of the auto-incrementing primary key for the new record is 123, they will be saved as:
/path/to/image/dir/123_foo.jpg
/path/to/image/dir/123_bar.jpg
Now when you want to grab the article out of the database, you will have to do a regular expression find and replace for the file names inside your mark up and remember to append the value of art_id for the record onto them to match them to the file names as they are stored in the file system.
Bookmarks