Question

How can I upload an image to a SQL database?

Current mysql query:

CREATE TABLE upload (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
 PRIMARY KEY(id)
);

html file

<form method="post"  enctype="multipart/form-data">
   <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
   <input type="file" id="userfile"  name="userfiles">  <br>
   <input type="submit"  id="upload" value="Uploadimage "name="uploads"onclick="upload()">      
</form>
Was it helpful?

Solution

I don't know about that SQL query, it doesn't tell much.

What you need to do is base64 encode the image and save this string to your database.
Similarly when you want to pull the image and display it, you will need to decode the string back to an image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top