[英]Weird Undefined offset: 0 error
I've the following PHP code that receives a file from an iOS app. 我有以下PHP代码,用于从iOS应用程序接收文件。
The information is received and for my debuggin $file
is setted and has content in all its forms. 接收到该信息,并为我的调试$file
设置并包含所有形式的内容。 The original value passed is btn-7.png
and $file[0] = btn-7
. 传递的原始值为btn-7.png
和$file[0] = btn-7
。
The function is processed and all images are copied to the system as I see them in the folder.... thus I dont know why i am getting this error. 该函数已处理,所有图像都复制到系统中,就像我在文件夹中看到的那样...。因此,我不知道为什么会收到此错误。
The error appear in the first line available to the function that shows $_FILES[$file]
错误出现在显示$_FILES[$file]
的函数的第一行
Does anyone have an idea why this is happening? 有谁知道为什么会这样?
EDIT: As I said. 编辑:正如我所说。 No need to do var_dump because I can echo $file. 无需执行var_dump,因为我可以回显$ file。 Also I am debbugin from iOS console can't see non-JSON results, I only rely on PHP logs to know the actual error message. 另外,我来自iOS控制台的debbugin无法看到非JSON结果,我仅依靠PHP日志来了解实际的错误消息。
EDIT2: as requested `var_dump(); EDIT2:根据要求`var_dump(); (I am working from XCode, iOS dev console, not web browser) (我正在使用XCode,iOS开发控制台而不是Web浏览器工作)
ob_start();
var_dump($file);
$e = ob_get_contents();
ob_end_clean();
error_log($e, 0);
the result 结果
[06-Jun-2013 17:58:26 UTC] string(9) "btn-7.png"`
the error 错误
[06-Jun-2013 17:24:45 UTC] PHP Notice: Undefined offset: 0 in C:\xampp\htdocs\igym\classes\shareexercise.php on line 146
PHP 的PHP
private function storeFile( $file )
{
$file = explode('.',$file);
$file = $file[0];
$msg['asd'] = $file;
echo json_encode($msg);
if( $_FILES[$file]["type"] !== "image/png" && $_FILES[$file]["size"] < 2048600 )
{
$error['error'] = 'There was a problem uploading your picture';
echo json_encode($error);
return 0;
}
if( move_uploaded_file( $_FILES[$file]['tmp_name'], IMGUPLOADDIR . '/' . $this->userID . '/' . $_FILES[$file]['name'] ) ) {
return true;
} else{
//$error['error'] = 'There was a problem uploading your picture';
//echo json_encode($error);
return false;
}
}
$_FILES
is an associative array, not a numerical array: $_FILES
是一个关联数组,而不是数字数组:
$_FILES
An associative array of items uploaded to the current script via the HTTP POST method.
You should var_dump($_FILES)
and see what the structure looks like. 您应该使用var_dump($_FILES)
并查看其结构。 0 doesn't exist because the index is the field name or some other string. 因为索引是字段名或其他字符串,所以不存在0。
Aso: A tutorial on $_FILES 麻生: 有关$ _FILES的教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.