Insert Images in MySQL from FTP
I currently use a third party software which I have setup to upload an image file every five minutes via the ftp server provided by my web hosting service.
The file is then stored in the "public_html" folder, don't worry about the rest of the path.
I want to store the image in a MySQL database. I have setup the database, and a table to except Blobs.
Can I:
A) FTP directly to the table in my database table?
or
B) Create a script to upload the image file everytime the "public_html" file is changed.
Does anyone know if either is possible, and if yes, how do I do it?
Thank you, and please let me know if you need more information.
Re: Insert Images in MySQL from FTP
Code:
CREATE TABLE tbl_images (
id tinyint(3) unsigned NOT NULL auto_increment,
image blob NOT NULL,
PRIMARY KEY (id)
);
`id` is the unique id for the table row. This is the primary key. `img_name` field stores the image name. `img_type` stores the information about the type of images like JPG or GIF etc. `img_size` holds the size of the image and img_data stores the actual image file.
Code:
// Create MySQL login values and
// set them to your login information.
$username = "YourUserName";
$password = "YourPassword";
$host = "localhost";
$database = "binary";
// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Select your database
mysql_select_db ($database);
Re: Insert Images in MySQL from FTP
Thank you Ackley for your response. I do have two questions more for you. I have a table already setup, and my primary key is of DateTime, because there can only be one picture at anyone given time. The update will be every 5 minutes give or take. Is this okay, or should I go with a integer PK?
Second, the database connect code, I need to build that out further in PHP script correct? I know that may be a basic question, but I am unfamiliar with PHP.
Thank you.