Advanced Search

Results 1 to 4 of 4

Thread: Vaildating the Contents of a file (needs to be moved to php)

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default Vaildating the Contents of a file (needs to be moved to php)

    I have a file upload input, I wanted to let only certian type of file through...

    heres what it looks like
    HTML Code:
    document.write("<br><input type='file' value='' name='FILENAME' id='file'/>")
    (The reason why its in document.write is to prevent the user from disabling javascript so he can disable the vaildation process and send fake stuff! because inorder to load the form you have to load the validation... (Smart I know)...

    If theres a way you can do this with if statements, I still don't know how, just give me the code and I'll be able to fit it in...
    I don't know that much Javascript but I know document.write fucntion. And all you have to check is if the last 4 letters are certain file types *make sure i can put more than one in there*. or if the file contains the file type ending... thanks!
    Last edited by Rockonmetal; 08-24-2007 at 09:17 PM. Reason: i forgot something and fixed it

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I would actually recommend instead of using javascript for this, to use PHP to validate the extension (assuming that's what you are using to upload the files if they pass validation). The way you can do that is be checking the $_FILES[] array for the extension and even further validation like the MIME type, file size, name, etc.
    Hope this helps
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    I think i already asked in PHP but I got so many wrong answers and i think after two pages it died, because i think everyone thought it was solved...

    but i'm gonna move this to the php section... to help keep people from getting mad...
    Last edited by Rockonmetal; 08-24-2007 at 09:41 PM.

  4. #4
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    I don't like document.write. It seems to lag the browser if it's called after the page has loaded. I use innerHTML. And yeah. Use PHP for validation. i don't know if you can stop people from putting a certain filetype in the box, but PHP could detect it and accept or not depending.

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
  •