View Full Version : Vaildating the Contents of a file (needs to be moved to php)

08-24-2007, 08:59 PM
I have a file upload input, I wanted to let only certian type of file through...

heres what it looks like

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!

08-24-2007, 09:15 PM
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

08-24-2007, 09:16 PM
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...

08-25-2007, 04:33 AM
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.