无法从具有 getID3 的数组中获取错误



我试图在搜索上传的临时文件时返回错误。

'

$getID3 = new getID3;
$file = $getID3->analyze($_FILES["file"]["tmp_name"]);
//print_r($file);
if (isset($file['error'])) {
    echo $file['error'];
} else {
    echo "
    <b>Duration:</b> " . $file['playtime_string'] . "<br/>
    <b>Dimensions:</b> " . $file['video']['resolution_x'] . "x" . $file['video']['resolution_y'] . "<br/>
    <b>Filesize:</b> " . $file['filesize'] . "bytes";
}

'

它存在于数组中,因为当我上传无效的文件类型时,它会返回此数组。

Array
        (
            [GETID3_VERSION] =&gt; 1.9.12-201602240818
            [filesize] =&gt; 159924
            [filepath] =&gt; /tmp
            [filename] =&gt; phpQAJeuD
            [filenamepath] =&gt; /tmp/phpQAJeuD
            [encoding] =&gt; UTF-8
            [error] =&gt; Array
                (
                    [0] =&gt; unable to determine file format
                )
        )

怎么不['error']

因为$file['error']是一个数组。数组无法回显。

您可以使用函数 print_r() 或通过循环打印数组的内容。

例如:

$arr = array('one', 'two', 'three');
foreach($arr as $value){
    echo $value."rn";
}

有关如何处理数组的更多信息,请参阅有关数组的 php 文档:http://php.net/manual/en/language.types.array.php

如果在任何情况下您不确定变量的类型是什么,则可以使用函数 gettype() 来解决此问题。另请参阅文档以获取更多信息:http://php.net/manual/en/function.gettype.php

>['error']是一个数组。

您需要输出['error'][0]

最新更新