SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi:

    Is there an effective way to restrict file uploads only to a certain type? I thought I could use the uploadedfile_type variable in PHP, but apparently that is determined solely from the file extension. That is, I was able to easily defeat it by changing the extension on a GIF file to "ZIP" to make it think it was a ZIP file. Is there a way for PHP to determine the REAL file type without regard to the extension? Thanks!

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There's no reliable way to do this without actually looking at the binary content of the file. The exact code will be very dependant on what kind of file you're trying to detect, and how thorough a check you want to make.

    Note also that this check can only be performed after the file has been uploaded to your server. You can only use the check to decide whether or not to process the uploaded file further.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •