Webserver - Detect Type of File

This is a discussion on Webserver - Detect Type of File within the C Programming forums, part of the General Programming Boards category; I am coding a webserver, and I would like to be able to detect what kind of file I am ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    16

    Webserver - Detect Type of File

    I am coding a webserver, and I would like to be able to detect what kind of file I am sending to the client, but I do not know of a good function for this, so if anyone could point me towards one, I would be very grateful.

    By file type I mean files such as JPG, PNG, HTML etc, so I can include the correct data in the header.

    I am coding pure C in a Unix environment.

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    983
    I assume the "obvious" (and error prone) method of looking at the extension has been examined and rejected?

    If you're on Unix, you have a "file" command. If it's a free Unix (and perhaps commercial ones), your "file" program is likely based on libmagic, which can determine file types quite accurately. Try "man libmagic". If you don't have it, you can download it from ftp://ftp.astron.com/pub/file/.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    16
    files is only accessible from the shell, is it not?

    either way, it wont work, since my computer is in some way defect and freezes indefinately when you use the make command, so manually installing new software is impossible.

    telling me to reformat is of no use since the problem lies with the hardware, but the producer (HP) have still failed to locate the problem after over 2 years, and instead are recalling this model, and I have broken the seal so I can not return mine *yay*.

  4. #4
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    983
    file is not only accessible from the shell, but I suggested using libmagic, not file.

    That doesn't solve your make problem, but if you have libmagic (not just file) installed, you can use libmagic; you don't need to run the file program.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Siphon View Post
    telling me to reformat is of no use since the problem lies with the hardware, but the producer (HP) have still failed to locate the problem after over 2 years, and instead are recalling this model, and I have broken the seal so I can not return mine *yay*.
    Ehm, if they are recalling the product, I would say that you should have the right to get a replacement/refund even if the seal is broken - why should instaling an extra hard-drive cause the recall to be invalid - it's not you installing the extra harddrive that caused the problems, right? [Installing an extra hard-drive is of course just an example, replacing the graphics card, extra network card, or whatever it is].

    I would have a chat with a HP support Supervisor about this case and make sure you explain to them that you do think it's unfair that just because you installed a second hard-drive [or whatever the reason you broke the seal is - don't say "I thought I could fix it by opening the box" of course - even if that was the reason] before you actually put the machine into it's real work, and you didn't expect it to have to be returned for a manufacturing flaw.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 03:44 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21