Home > Programming > PHP >

How do i upload a binary/image file to SQL server



I dont have an example for this because i havent uploaded files to SQL server. When i started working on my intranet project, I needed to find a way to save my scanned images to the SQL Server.. This is actually very easy if you are running MYSQL server. But for me NOT, im running MSSQL server and that is much more difficult to work with when it comes to Binary files. First of you have to encode the file your want to upload and second you have to split it up into smaller trunks and then updating each part into your binary column on MSSQL server.

Why i stopped figuring out how this works was because that every example i read, told me NOT to save the file to a Database, but instead saving it as a file on the server filesystem and then only saving the filename into your database.. WHY? because saving BIG files into your SQL Server makes it slower and slower. And there is no way around this so i recommend you to not save the file into your database but infact saving it in a folder on your server. That is also easier for maintenance and will not slow down performance of your SQL server.

So i clearly recommend if you want to upload files to your server, dont save it to your database, just save the filename.

How do i upload the file to the server then?

You can make a FORM and then a INPUT FILE. You then POST the data to a page handling your $_FILES array which PHP creates for you. then using the file component in PHP to save it to a specified folder on your server. Remember PHP needs permission to write to the folder


Keywords : UPLOAD | PHP | FILE | BINARY | IMG | MSSQL

Click here for more PHP Examples