Thread: uploadfile()
View Single Post
  #16  
Old 07-24-2009, 11:47 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Switch View Post
PHP Code:
temp.allowed = {"graal","nw","gani","png","gif","mng"}; //still don't get mng :\
temp.fileName.tokenize(".");
if (!(
t[fileName.size()-1in allowed)) {
  
//stuff code stuff

Pretty sure that could be used, just replace fileName with whatever you're using to get the file name. Not 100% on that since I don't know if it's possible to check the name.
Checking file extensions won't prevent malicious users from uploading executable files. You need to check file headers. Essentially, you would use loadlines() to load the first line of the file, and you would check if the file header is located within that. (For instance, GIF files always start with "GIF8").

In the end, though, there's nothing you can do if somebody really wants to upload malicious files. Even checking headers doesn't do much, since the person can simply edit the file header. Hopefully getting an error, even after they've changed extensions, would just make them give up.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote