未定义偏移量:0错误


Weird Undefined offset: 0 error

我有以下PHP代码从iOS应用程序接收文件。

收到信息,为了调试,设置了$file,并具有所有形式的内容。传递的原值为btn-7.png$file[0] = btn-7

处理该函数并将所有图像复制到系统中,就像我在文件夹....中看到的那样因此,我不知道为什么我得到这个错误。

错误出现在显示$_FILES[$file]的函数可用的第一行

有人知道为什么会发生这种情况吗?

编辑:如我所说。不需要执行var_dump,因为我可以回显$file。此外,我从iOS控制台调试无法看到非json结果,我只依靠PHP日志来知道实际的错误消息。

EDIT2: as requested ' var_dump();(我是从XCode, iOS开发控制台,而不是web浏览器工作)

ob_start();
            var_dump($file);
            $e = ob_get_contents();
            ob_end_clean();
            error_log($e, 0);
结果

[06-Jun-2013 17:58:26 UTC] string(9) "btn-7.png"`

错误

[06-Jun-2013 17:24:45 UTC] PHP Notice:  Undefined offset: 0 in C:'xampp'htdocs'igym'classes'shareexercise.php on line 146
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是一个关联数组,而不是一个数值数组:

从:php.net

$_FILES
An associative array of items uploaded to the current script via the HTTP POST method.

你应该var_dump($_FILES),看看结构看起来像什么。0不存在,因为索引是字段名或其他字符串。

$_FILES
教程