I have heard that it is bad form to upload a file directly into your database table. This is supposedly slow and cumbersome once the table gets large. So to get around this I think the preferred method is to save the file to a folder on your server, but to save the PATH into your table.
Say you have a form that allows users to create posts, and with it they have the option of including one image. Most of the steps on how to do this are readily available online. BUT…
I have not found anyplace that thoroughly explains how to prevent people from uploading files with the same name. I’ve heard of using random numbers, or something like that, but that’s unsatisfactory if your table gets large.
In my database, the user posts have their own table, and the image path is one of the columns. Another column is the post_id, which auto-increments. I would like to be able to save the file name to match the post_id number.
The only thing I can think of is to run a mysql query, insert the data into the table (without the file!!!) and then run another query, see what the id number is, and then rename the file, and then do another query and upload it after…But I don’t want to do some ridiculously stupid programming if there’s a better way.
All suggestions are appreciated.