Results 1 to 3 of 3

Thread: Validating File Uploads

  1. #1
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default Validating File Uploads

    I need a way to validate uploaded files, meaning that they actually got there OK as a working copy. I came across a function, sha1() and the man page is at http://us2.php.net/sha1_file. And there is MD5() found at http://us2.php.net/manual/en/function.md5-file.php. And also crc32() at http://us2.php.net/manual/en/function.crc32.php. So, which one is the right way to go, and how should it be implemented into an upload function? I'm hoping that someone has experience in this area......

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Any of them will do fine. MD5 is the most common algorithm, with SHA1 following. CRC32 is rarely used, but can be provided as an alternative.

    The trickiest bit will be obtaining the checksum from the client. Since by the time it's reached the server it could be corrupted, this must be done client-side. That will require Java, or for the user to enter the checksum manually (or even better, Java with a manual fallback).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yeah, as Twey says, there's really no point to this unless you have a value to compare it against. How do you plan to do that?

    I'd say use md5, just 'cause it's the most common, and people might even have the md5 version of the file from downloading it, or something else. Security shouldn't be an issue, so I'd just choose based on popularity.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •