1

I'm trying to get an error to return when I search the temporary file that is uploaded.

`

$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";
}

`

And it exists in the array because when I upload an invalid file type it returns this array.

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
                )

        )

How is it not getting ['error']?

Cameron Swyft
  • 448
  • 2
  • 6
  • 21

2 Answers2

2

Because $file['error'] is an array. Arrays cannot be echoed.

You can print the contents of an array by using the function print_r() or by looping trough it.

For example:

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

See the php documentation on Arrays for more information on how to handle them: http://php.net/manual/en/language.types.array.php

If in any case you are not sure what the type of a variable is, you can resolve that by using the function gettype(). Also see the documentation for more information: http://php.net/manual/en/function.gettype.php

Fin
  • 386
  • 1
  • 15
1

['error'] is an array.

You need to output ['error'][0]

Vasil Rashkov
  • 1,818
  • 15
  • 27
  • 1
    Yea I won't lie, RIGHT when I posted this I literally saw my problem... I really should head to bed LOL. Anyways thanks :P, apologies for terrible post :) Enjoy free answer EDIT: Have to wait 8 mins – Cameron Swyft Mar 09 '16 at 20:23