Results 1 to 3 of 3

Thread: Insert Images in MySQL from FTP

  1. #1
    Join Date
    Jul 2009
    Posts
    3

    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.

  2. #2
    Join Date
    Dec 2008
    Posts
    183

    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);

  3. #3
    Join Date
    Jul 2009
    Posts
    3

    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.

Similar Threads

  1. How to Insert data into MySQL table
    By Mahendra varma in forum Software Development
    Replies: 4
    Last Post: 04-10-2009, 04:42 AM
  2. How to perform Insert on duplicate key update in MySQL
    By Xena in forum Software Development
    Replies: 3
    Last Post: 18-05-2009, 09:49 PM
  3. How to insert GetDate() function in MySQL
    By Shanbaag in forum Software Development
    Replies: 3
    Last Post: 18-05-2009, 05:40 PM
  4. Batch insert on MySQL is possible
    By Shreevats in forum Software Development
    Replies: 3
    Last Post: 16-05-2009, 06:13 PM
  5. how to insert a image in mysql
    By cnu0870 in forum Software Development
    Replies: 5
    Last Post: 28-04-2009, 05:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,470,948.75668 seconds with 17 queries