Home:ALL Converter>PHP fread() expects parameter 1 to be a resource, boolean given

PHP fread() expects parameter 1 to be a resource, boolean given

Ask Time:2018-02-06T06:19:48         Author:Alex

Json Formatter

I have this errors, the thing is on local server is working just fine, but now when i uploaded the files to the hosting i get these errors.

  • fread() expects parameter 1 to be resource, boolean given
  • fseek() expects parameter 1 to be resource, boolean given
  • feof() expects parameter 1 to be resource, boolean given

Some help needed..

PHP Script:

public function getDuration($use_cbr_estimate=false)
    {
        $fd = fopen($this->filename, "rb");

        $duration=0;
        $block = fread($fd, 100);
        $offset = $this->skipID3v2Tag($block);
        fseek($fd, $offset, SEEK_SET);
        while (!feof($fd))
        {
            $block = fread($fd, 10);
            if (strlen($block)<10) { break; }
            //în căutarea pentru 1111 1111 111 (biți de sincronizare a cadrelor)
            else if ($block[0]=="\xff" && (ord($block[1])&0xe0) )
            {
                $info = self::parseFrameHeader(substr($block, 0, 4));
                if (empty($info['Framesize'])) { return $duration; } //unele fișiere mp3 corupte
                fseek($fd, $info['Framesize']-10, SEEK_CUR);
                $duration += ( $info['Samples'] / $info['Sampling Rate'] );
            }
            else if (substr($block, 0, 3)=='TAG')
            {
                fseek($fd, 128-10, SEEK_CUR);//sărim peste dimensiunea etichetei id3v1
            }
            else
            {
                fseek($fd, -9, SEEK_CUR);
            }
            if ($use_cbr_estimate && !empty($info))
            { 
                return $this->estimateDuration($info['Bitrate'],$offset); 
            }
        }
        return round($duration);
    }

Author:Alex,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48632421/php-fread-expects-parameter-1-to-be-a-resource-boolean-given
yy