打開 CodeIgniter 的代碼( system/libraries/Upload.php )
/**
* Verify that the filetype is allowed
*
* @access public
* @return bool
*/
function is_allowed_filetype()
{
if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
{
$this->set_error('upload_no_file_types');
return FALSE;
}
$image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');
foreach ($this->allowed_types as $val)
{
$mime = $this->mimes_types(strtolower($val));
// Images get some additional checks
if (in_array($val, $image_types))
{
if (getimagesize($this->file_temp) === FALSE)
{
return FALSE;
}
}
if (is_array($mime))
{
if (in_array($this->file_type, $mime, TRUE))
{
return TRUE;
}
}
else
{
if ($mime == $this->file_type)
{
return TRUE;
}
}
}
return FALSE;
} php
咱們這裏要解決的問題是讓它能接受任何類型
它判斷了若是沒有設置 allowed_types 時,它也會返回 false,這個代碼塊改爲以下
this
if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
{
// $this->set_error('upload_no_file_types');
// return FALSE;
return TRUE;
}
spa