Load picture using an URL MYSQL

66 Views Asked by At

I want to know If there is any way to load an image into a table like:

CREATE TABLE MyTable( id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, images BLOB NOT NULL,

INSERT INTO MyTable (image) VALUES(LOAD_FILE('/tmp/your_image.png'));

But also if i can add an url instead of the path to my image:

INSERT INTO MyTable (image) VALUES(LOAD_FILE('https://imgur.com/gallery/6rKiG'));
1

There are 1 best solutions below

0
On

You can try this:

INSERT INTO x(id,pic) VALUES(1,LOAD_FILE('C:/Desktop/images/test.jpg'));

And then with PHP (for example) you can read and print

/*
Read from database
...
... */
echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['pic'] ).'"/>';

For reference LOAD_FILE