0

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);
    }
lotfio
  • 1,916
  • 2
  • 18
  • 34
Alex
  • 50
  • 9
  • 1
    if `$fd` is a boolean, it means the file couldn't be opened. (The reason for that isn't going to be apparent from this code, though.) – Don't Panic Feb 05 '18 at 22:22
  • Have you checked if the file actually opens or not??? Have you check `fopen` documentation? – Eric Feb 05 '18 at 22:23
  • It's part of programmer's job to debug. Comment out `$duration=0` to all the way after `return round($duration)`. Then just check the value of `$fd`. – Eric Feb 05 '18 at 22:26
  • I think the most likely possibility is that you're trying to store your files in an inaccessible directory on the hosting server that was accessible on your dev server. – Don't Panic Feb 05 '18 at 22:26
  • 1
    @Eric the file doesn't open. The errors already tell us that. The only way a boolean can be passed to fread, etc. is if fopen fails and returns false. – Don't Panic Feb 05 '18 at 22:27
  • I'm new with this, and i don;t have the knowledge .. if someone could help me.. – Alex Feb 05 '18 at 22:50
  • @Don'tPanic , yes, that i'm trying to do – Alex Feb 05 '18 at 23:03
  • 1
    it's a good idea to do a `file_exists()` before running `fopen()` to make sure your path is correct in the first place. Print the file path and you will see your problem – Ibu Feb 05 '18 at 23:07
  • Can you show me how please? – Alex Feb 05 '18 at 23:42

0 Answers0