Jump to content

Uploading Image data to Database


ksn_prasad

Recommended Posts

In one of my web-application with PHP-MSSQL-IIS, I got a problem. Please give me some suggestion.

 

A database table contains a column 'icon' of type varbinary(max), where I have to insert the image data to it. There is a stored procedure to insert the data to that table. I am using mssql connector to access the database.

 

I read the contents of the image file to a variable using fread() or file_get_contents().

Now I made a query using mssql_init() and tried to bind the variables with the query using mssql_bind().

Here I got the problem. I don't know, how to bind the binary data. If I use SQLVARCHAR, it is not binding.

 

I tried to use the same after using addslashes(), still it is not working.

I tried to convert the data to Hexa decimal format using unpack() function, and then attempted to bind the data. Still it is not working.

I didn't find any other PHP constant other than SQLVARCHAR that matches to send the Binary data.

 

If I convert the data to Hexa Decimal using unpack function and insert the data to the table directly without using stored procedure, using mssql_query() it is working fine (remember not to enclose the icon data in single quotes, where other varchar, text, date values should be enclosed). But still I should not follow this way. I should use the stored procedure given by my database admin. Please let me know some clue, how to handle mssql_bind() to bind binary data.

Link to comment
https://forums.phpfreaks.com/topic/203487-uploading-image-data-to-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.