Upload A File Into My Database

Hi All

I want to upload a file into my mySQL database using PHP so I can encrypt it and someone can’t just download it.

I am sure this is possible however all the tutorials I can find are about uploading the file onto my server and saving the filename/path into the database.

Can you please point me in the right direction to find code to upload a file into my database or give me some ideas of what to Google for as what I am searching for is not working.

Many Thanks


you receive a file name starting /tmp/... in your $_FILES, that’s the image. You can read it with file_get_contents into a string and do whatever you want with it. But mixing up “download” and “encrypt” doesn’t really make sense.

Surely there are other ways to achieve this? Encrypt it on upload, and have it on the server in a location that cannot be accessed by the outside world i.e. above your web root. Then the only way anyone can get to it is to sign into your site, and your code serves it to them, perhaps decrypting it as part of that process.

1 Like

If the main purpose is so people can’t download those files, there are plenty of ways to achieve this. There is no need to be storing those files in the physical database. The thing about having the physical files on a server is that you can view them at anytime. Plus the ease of looking for what you want.

Thanks… that is a good idea to store then below the public_html folder so that someone can’t just get the files… they are all my business and personal receipts that I really don’t want someone just stumbling across… thanks for your help.

Why would you want to store those on a website though? Something like dropbox or similar seems better suited for those kinds of documents.

above the public_html folder, or in my head at least. To me, folders below it are those that are accessible: public_html/images and so on.

But as @rpkamp said, maybe some other kind of storage might be better, though of course on your own web site means you could knock up some code to keep track of them rather than have to think up some elaborate file naming scheme.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.