Jump to content

How To Insert Img Into Mysql Column ?


phpsane

Recommended Posts

Php Buddies,

Just how do you insert an uploaded img via html for ($_POST) to mysql tbl and what type of column should it be ?

Also, how to link the img from the mysql column to a webpage ?

Following html links the img from a folder/directory to a webpage:

<a href="../html-link.htm"><img src="flower.jpg" style="width:82px; height:86px" title="White flower" alt="Flower"></a>

Link to comment
Share on other sites

Either you store the uploaded file as a file on your server and your database has information about it (like path and file type), or you store the data directly in the database. The former is much more common.

How you link to it depends on which option you choose and whether you want the files to be publicly-accessible by anyone.

Link to comment
Share on other sites

Here's a tutorial about storing a blob using mysqli that covers some very important aspects of this problem, in particular the mysql 'max_allowed_packet' setting.

There is a substantial cost to storing blobs in a relational database which is why it is often avoided.  Conversely there is simplicity and security in knowing that your database is complete, and backing up your system doesn't involve separate maintenance of the filesystem separately.

With blobs in a db, you pay an extra price for retrieval:  

PHP retrieves BLOB from DB  into PHP Memory -> PHP Returns to HTTPD  -> Client

With filesystem storage, which often has a native OS buffer, it can return the files directly to the client if the files exist in webspace.  

HTTPD -> Client

PHP doesn't have to be involved at all, unless you have a scheme that keeps the images off the webroot due to some security requirement, and even if you don't, you can  use readfile to dump the file directly to the output buffer.

 

 

Link to comment
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.