I've been looking all across the internet for help on this and have found nothing.
Basically I need to know how to update a SQL Server VARBINARY(MAX)
column with the hex of an image uploaded from a HTML form. The database is in a different place to the HTML form, so move_uploaded_file
in PHP then OPENROWSET (BULK ...)
in SQL doesn't work (unable to find the file).
I also tried doing file_get_contents
on the uploaded $_FILE['name_']['tmp_name']
, then used unpack("H*hex")
and put the result of that into the SQL column with a "0x" prepend, but that crashes, saying it needs to be converted from a VARCHAR
to a VARBINARY
. When I convert it, the code runs and the column is populated, but the image is malformed.
No idea what to do next. Pls help.
Solution:
This is a basic approach using PHP Driver for SQL Server:
Table creation (T-SQL):
PHP: