i have looked all over the web on how to upload a file to MySQL database and retrieve using coldfusion. I know i can do it in PHP, but im not using that anymore. Is there a script or some place that someone can point me so i can learn? I know i can move the file to a location and store the link, but was hoping to find a way to store it in MySQL?
You mean store the file content in the db, not just the file path (ie "c:\path\myImage.gif")? While you can do it, it can drastically bloat your database. But if you really want to do it, here is an example. It's for Oracle but the overall process is the same for any db.
Just upload the file as usual ie using <cffile action="upload" ...>. But instead of storing the file path, you read the *contents* of the file into a variable. Then insert the variable's binary data into the database instead of the path. When you're done, you can delete the uploaded file.
Retrieving the file from the db is the same as any SELECT. Just retrieve the record, and use CFCONTENT, with the proper mime type to display it in the browser. If you need any help with that part, just let me know.
Thanks for that one. Well i got it working just like in the example that was provided where i can upload and download.
My only question is, how do i get the Filename and File Extension? Reason is, because now i dont have to manually specify the name and extension or just restrict the upload to certain types of files.