2012-09-09 95 views
1

我有一些PHP代码检查用户上传的文件类型:PHP +允许上传JPG文件

$fileType = $_FILES['file']['type']; 
    $allowedFileTypes = array('image/jpeg','image/gif','image/png','image/jpg'); 
    if(!in_array($fileType, $allowedFileTypes)) {echo 'fileTypeNotAllowed'; exit;} 

我发现GIF & PNG文件上传不触发回声但JPG文件引发的回声。

下面

是触发回声文件的例子:

enter image description here

上,我做错了什么在这里任何建议?

THX

+4

echo $ fileType上传JPEG时看到它说什么 –

+4

也许你的代码不会允许海滩照片 – Tchoupi

+3

$ fileType包含什么? 'echo'fileTypeNotAllowed:'。$ fileType;' –

回答

1

好了,要检查他们所上传...所以我会用!in_array(strtlower($的fileType,$ allowedFileTypes))in_array。

这应该清除一切。