The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Is there a particular reason you need the files to be in the database? I did a site that stored large files in MySQL once, and it slowed the database server to a grinding halt. You may find it preferable to store the files in the filesystem with each file's MD5 hash as the filename, then put the filenames and any other desired information about the files into the database. Not only would this be more efficient, it would save a lot of tinkering with the database configuration files.

Do you mean that importing date from .csv and .doc files? If not World Wide Weird's idea is the best one instead of storing the files. If you mean to importing the data from CSV files then there are some functions like fgetcsv() in PHP see the manual. And uumm about the .doc you have to read the data with file handing functions.

I dont think that there are such particular tutorials for it but you need to integration some things to one for your goal. Like upload file with some move_uploaded_file() or copy() for uploading the browsed files and you can get lots of file information with $_FILES array i.e. $_FILES['browsefile']['tmp_name'], $_FILES['browsefile']['type'], $_FILES['browsefile']['size'] etc.

I could not be clear about your short description but from the what i could understand; you can insert the ID to some extra field in the table while inserting the file name. Also you can concatenate the ID with the filename too.

PHP Code:

$filename = $id . "_" . basename($_FILES['file']['name']);

Or insert the id in your database table separately like this:

PHP Code:

mysql_query("insert into tablename set id='$id',filename='$filename'") or die(mysql_error());

// get the name of the uploaded file$filename = basename($_FILES['file']['name']);// select a random number from 1 - 999$id = rand(1, 9999);//concatenate the two vars$new_filename = $filename ."_" .$id;

You can then insert the new filename into the db along with the other details for referencing ...

Sorry, I should have been more specific, my code was a kittle incorrect.

PHP Code:

// get the name of the uploaded file$filename = basename($_FILES['uploadfile']['name']);// select a random number from 1 - 999$id = rand(1, 9999);//concatenate the two vars, and add the extension$new_filename = $filename ."_" .$id.".wps";

That should give you "Chris CV_randommnumberhere.wps"

Additionally, what I normally do for this sort of thing is the following:

PHP Code:

$filename = basename($_FILES['uploadfile']['name']);// get rid of spaces and convert all letters to lower case$filename = strtolower(str_replace(" ","",$filename));//put together the new name$new_filename = $filename ."_" .$id.".wps";

If you're going to store only one file per user you might store the filename in the database but have the real file renamed to $id.doc or $id.csv.

Another way is to just create a folder for each user in the database. For example users/$id/ and upload their files there. I generally do this for scalability. So if tomorrow the user wants to add pictures or other media i would just add subfolders like: users/$id/pics/, users/$id/music/, etc.

I have created a form and now the file is uploaded to a folder on my server.
The problem is how do I assign a id to the file so that I know who upload the file?

What I do in my forum's image dump is MD5 the file and use that as the filename. Not only does it provide a unique filename, it helps ensure every file is unique. Thus, if someone else subsequently uploads an identical file, the script informs them that the file already exists.

Once you've done that, you simply put the MD5 filename in the database along with the original filename or the user-defined virtual filename.