Hi guys,
I'm wondering how would you convert the exact file into binary so that I can save that binary into the database. Any ideas?
Printable View
Hi guys,
I'm wondering how would you convert the exact file into binary so that I can save that binary into the database. Any ideas?
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).
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>
Thank you so much for replying guys.
paulinetaylor85, im not quite sure how that works. do you have some php codes?
You can use the GB library for PHP to do this, take a look at the imagecreatefromstring function.
Thank you for your replies guys,i was interested by the thread.