Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help wanted with file upload..!!

    I am working in PHP/MySQL and wanted to upload a file to Mysql database. I am having these problems:
    1. the .doc files are not getting uploaded to Mysql database.
    2. how do you retrieve the file from the database in another PHP script?

    Thanks in advance.

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    You'll need to post your code...

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Code would definitely help.
    Without it, I can still give you some pointers. First and foremost, you're database must be using a binary object type for its field of appropriate length. This will likely be a mediumblob field.
    Next, the algorithm:
    - open file.
    - read file into binary string (php will use binary by default since pre-5.3 binary is not a cast type).
    - write binary data to the database.

    Read works about the opposite. Since you're dealing with .doc files, php cannot handle those for display. You simply query the database, pass the appropriate headers to force a download, and print the binary data thats been retrieved from the database.

    You can actually store this as base64 encoded in a text type field instead of blob style, but that takes what.... 3 times as much data I believe it is.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •