unexpected file type during upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

unexpected file type during upload

Post by yacahuma »

I am uploading a pdf and I am getting this on the $_FILES array

Array
(
[userfile] => Array
(
[name] => diyautoparts.pdf
[type] => application/force-download
[tmp_name] => C:\Windows\Temp\phpFD61.tmp
[error] => 0
[size] => 40449
)

)
I was expecting application/pdf. Can someone explain? Thank you
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: unexpected file type during upload

Post by Benjamin »

I would assume that the variable comes from the browser and therefore cannot be relied on.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: unexpected file type during upload

Post by requinix »

Benjamin wrote:I would assume that the variable comes from the browser and therefore cannot be relied on.
Yes. Yes yes yes. Very yes.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: unexpected file type during upload

Post by yacahuma »

What are the alternatives? I now there is fileinfo in 5.3 But I dont have 5.3 available
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: unexpected file type during upload

Post by requinix »

5.3 merely has fileinfo built-in. You can still get it separately for PHP <5.3.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: unexpected file type during upload

Post by yacahuma »

how?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: unexpected file type during upload

Post by Eran »

User avatar
JAY6390
Forum Newbie
Posts: 20
Joined: Sat Apr 17, 2010 6:51 am
Location: UK

Re: unexpected file type during upload

Post by JAY6390 »

Never rely on the mime types given for uploaded files since with header injection its possible to change them to whatever a hacker wants to
Post Reply