SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: attachments

  1. #1
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    attachments

    Hello

    I am creating a message board and I was thinking of allowing attachments. This is how I plan to do it
    Create a seperate table from the posts table that stores

    id int not null primary key
    Post_id int not null
    attachment BLOB not null
    filename varchar(100) not null
    extension varchar(10) null

    Then when I receive a file via $_FILE array, how would I insert it directly to the database?
    Also I would likely create some file attachments.php that would need the value id which shows the postid, how would I output it? I mean like here, what headers would I send out for
    .doc
    .jpg (image/jpeg)?
    .png (image/png)?
    .gif
    .bmp
    .pdf
    .psd
    .txt (text/plain) ?
    .zip
    these are what I remember now (those valid on vbb :)
    And how would I extract the file from the database to the file? just echo the db field after sending the header?
    and how would I let the file keep it's name when downloaded?
    and how would I force user to download (so .doc .pdf files aren't opened within the browser?)

    Thanks in advance!
    - website

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow, you have a lot of questions there. i'll just make some brief comments.

    i wouldn't store the files in the DB, but as regular files and just store stuff like filename, type, etc. in the DB.

    as far as keeping the filename, i think you send a header like this:

    header("Content-Disposition: attachment; filename=$filename");

    i think that will also force a download...? otherwise, you can use this header, i think

    header('Content-Type: application/octet-stream');

    not sure about how to do the different content-types. (.gif is image/gif BTW.) without creating a list of extensions and their type, i'm not sure what to do. you might try storing the value of $_FILES['attachment']['type'] when it's uploaded. i'm not sure if that's always accurate or if there's any issues with it.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, my board is going to be nice
    Well, as you see eg here on vBulletin they only allow certein types of attachments, I thought that they were maybe limited with the headers available in the code. But why not store it in the database, well I could maybe store the attachement in some folder above wwwroot and just name it 1 2 3 4 after the id of the attachment in the database or something, then I would use the php file to act as the file when someone tries to download it.
    But how is it here eg on vB, do they just rename the file after the id or do they store it in the database?

    and btw, thanks for helping my in all my posts!
    - website

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my board's going to be nicer.

    vB 2.x stores attachments in the DB, but because this was so inefficient with lots of attachments, they are storing them in the filesystem in vB 3.

    BTW, you're welcome.

  5. #5
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my board's going to be nicer.
    Well, I don't doubt that, is it going to be open source?

    Either way I will yes propably do it the filesystem way, declare some folder attachment folder above wwwroot and then save the files by id of attachment with no . ending, Then I will just send out right headers and user will propably get it right.

    Well, when I run into questions about how to do it it I will defenatly post back here and anny you
    - website


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
  •