My first suggestion is to not save the image file in the database, as the file system itself is a more efficient way to access, well, files. (You can store data about the image in your DB, including directory and file name info so you know where to get it.)
If you are still determined to do so, then all you need to do is create a BLOB type column in your DB, and insert the contents into it (probably using file_get_contents() to grab the file contents).
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Try with below code to convert image file into binary.
<script>
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
var img = new Image();
img.onload = function () {
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
var data = canvas.toDataURL("image/jpeg");
alert(data);
};
img.src = "http://localhost/MvcApplication3/test.png";
</script>
Bookmarks