Inserting Graphic into MySQL Database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jsilver
    Junior Member
    • Sep 2004
    • 26

    #1

    Inserting Graphic into MySQL Database

    I am working on a site at www.interquipcanada.com but am having issues uplaoding graphics. The client is supposed to be able to go to www.interquipcanada.com/manager/admin.php in order to fill out a form and upload the info and graphics. The info that is uploaded automatically shows up in the products section of the site...but the image won't write to the appropriate folder.

    Any ideas?

    I could really use some help.

    John Scott
    Last edited by jsilver; 05-18-2005, 11:03 PM.
  • -Oz-
    Senior Member
    • Mar 2004
    • 545

    #2
    if you want the graphic to go in the database it needs to be a blob type field. If you want it to go into a folder make sure you chmod the folder 777.
    Dan Blomberg

    Comment

    • furpcom
      Junior Member
      • Jun 2004
      • 13

      #3
      Here is the code I wrote to load an image in to MySQL

      There is lots of error checking and other processing I did not want to bore you with, but you should be able to get the idea. This code has been in production for some time and I don't know of any problems, but that does not mean there are not any

      $handle = fopen($_FILES['userfile']['tmp_name'],'rb');
      $file_content = fread($handle, filesize($_FILES['userfile']['tmp_name']));
      fclose($handle);
      @mysql_query("UPDATE files SET file_type='" . $image_info['mime'] . "', width='" . $image_info[0] . "', height='" . $image_info[1] . "', data='" . base64_encode($file_content) . "' WHERE user_id='" . $_SESSION['user_id'] . "' AND file_id='mainpic'");
      if(mysql_affected_rows() == 0) {
      @mysql_query("INSERT INTO files SET user_id='" . $_SESSION['user_id'] . "', file_id='mainpic', file_type='" . $image_info['mime'] . "', width='" . $image_info[0] . "', height='" . $image_info[1] . "', data='" . base64_encode($file_content) . "'");
      }
      echo '<h3>Picture successfully saved.</h3>';

      Comment

      • jsilver
        Junior Member
        • Sep 2004
        • 26

        #4
        It works now. Thanks guys.

        Comment

        Working...