Welcome, Guest
  • Author Topic: How do I upload a user image into my MySQL database?  (Read 7244 times)

    Jaylada

    • Seasoned Programmer
    • ***
    • Posts: 144
      • View Profile
      • Email
    Once I have the path name of the users image, how do I allow them to upload it into my database?

    Thanks in advance
    J

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    First of all some things to be made clear:

    You want a user to upload an image
    Then this image should be stored in the database
    What about the Path?

    A common methode storing images, is using space on the filesystem of the server.
    Then you just write the path and filename into the database.
    When you want to retreive the image, you read the database record, to findout about the path, and then send the complete path (added with the server section) to the browser or flash clip to be loaded.

    Sometimes, usualy for security reasons, people store the image in a blob-field inside of the database.
    I think, this is not what you wanted?
    You can handle an image like a binary block of string. This is then stored to the database.
    Reading is a little more complicated, because the link to the browser is the script retreiving the image, having a image header and sending the image from the database.
    happy flashing
    8)
    Ronald

    Jaylada

    • Seasoned Programmer
    • ***
    • Posts: 144
      • View Profile
      • Email
    I've allowed the user to type in the path name, local on their computer to store.
    I do need to have security in mind, so I will look into the Blob field.  Currently the only image types I plan to let them upload are .jpg or .png, hopefully that is compatable with a blob field....?  This is the binary block of string method you talk about?

    The method where you say store the file on filesystem of the server, is there a secure method to do this?

    Thank you for the help, this is very helpful knowing where to start.
    J

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    usualy the upload section is separated and, if you do it with php, you can control, where the file will be stored.
    The section, where images reside, is set to not executable.
    You name the file as you like - for instance, make all images to be jpg, resize them, before you store them - etc.
    For those operations you can use the GD library of php.
    You can limit the size, a user can upload.
    Even when you store the image in a blob field, first the server loads it into a temporary file.

    For details read the php manual about the image manipulating methods and commands.
    happy flashing
    8)
    Ronald

    Elwood4Pena

    • Server what's that
    • *
    • Posts: 1
      • View Profile
      • Email
    You instead save the image to your server, but keep a record in the database of what file was saved so you can easily reference the image when needed.
    This will be more convenient.