非法抵消类型 [英] Illegal offset type
问题描述
我无法通过php上传文件。我在流程开始时检查了文件类型,并收到错误消息。
这是我得到的错误:
警告:
/balblabla/DBfunctions.inc.php中的非法偏移类型
183
打印出$ _FILES var
$ b
Array([图片] => Array([name] =>
JPG.jpg [type] => image / jpeg
[tmp_name] => / tmp / phpHlrNY8 [error]
=> 0 [ )
下面是我使用的代码段,我的问题:
$ $ p $ 函数checkFile($ file,$ type)
{
if(in_array($ _FILES [$ file] ['type'],$ type)){//< --- LINE 183
return true;
} //如果
返回false;
} // end checkFile()
这是调用函数的代码行($ _FILES ['Picture'],array(image / jpeg))== true){ >
//做的东西
} //结束如果
我已经使用这块代码在我自己的服务器上的几十个网站上,所以我猜测这是一些不同的配置选项。我怎样才能修改我的代码,以便它可以在这个不同的服务器上工作?
checkFile
函数。要解决这个问题,请进行以下更改之一:
更改checkfile,以便使用传入的数组执行检查,因此:
$ b $ p
$ b $ p $ if $($)$调用这个函数的代码,以便它传递文件的名字作为索引而不是文件数组,这样:
if(checkFile('Picture',array(image / jpeg))== true)
或者更改都可以。
I am having trouble uploading a file through php. I check the file type at the beginning of the process and I get an error.
This is the error I am getting:
Warning: Illegal offset type in
/balblabla/DBfunctions.inc.php on line
183
This is the printed out $_FILES var
Array ( [Picture] => Array ( [name] =>
JPG.jpg [type] => image/jpeg
[tmp_name] => /tmp/phpHlrNY8 [error]
=> 0 [size] => 192221 ) )
Here is the segment of code I am using that is giving me issues:
function checkFile($file, $type)
{
if( in_array($_FILES[$file]['type'], $type) ){ // <--- LINE 183
return true;
}//if
return false;
} // end checkFile()
This is the line of code that calls the function
if( checkFile( $_FILES['Picture'], array("image/jpeg") ) == true ){
//do stuff
}// end if
I have used this piece of code on dozens of websites on my own server so i am guessing that this is some different configuration option. How can i modify my code so that it works on this different server?
解决方案 You are passing an array, not a string/integer index to your checkFile
function.
To fix this, make one of the following to changes:
Change checkfile so that it uses the array passed in to do the checking, thusly:
if( in_array($file['type'], $type) )
OR change the code that calls this function so that it passes the name of the file to use as an index rather than the file array, thusly:
if( checkFile('Picture', array("image/jpeg") ) == true )
Either change will work.
这篇关于非法抵消类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!