error "supplied argument is not a valid stream resource" with fread()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bobzillaforever
    New Member
    • Mar 2008
    • 4

    error "supplied argument is not a valid stream resource" with fread()

    I'm unable to get the file(s) in question to read with file_exists(), fread(), or probably any similar function. I've tried it with .txt, .flv, .pdf, .mov, .mp3, and .wmv. I've tried removing the following from my .htaccess file to no avail.

    Code:
    <FilesMatch "\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">
      Order allow,deny
    </FilesMatch>
    I've also tried adding the following to my .htaccess file, which was also unsuccessful.

    Code:
    AddType text/plain txt
    I know that the files themselves are error-free and the correct URL is being delivered.

    Here's the relevant code from my .php file:
    [PHP]
    $yy = date('Y', $created);
    $mm = date('m', $created);
    $dd = date('d', $created);
    $yymmdd = $yy.$mm.$dd;
    $flv = base_path() . 'files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd . '.flv';

    if (file_exists($f lv)) {
    // my code
    } else {
    echo '<p>file ' . $flv . ' doesn\'t exist.</p>'; }
    var_dump(file_e xists($test));
    echo '<br />';
    fread($test, 8);[/PHP]
    The last three lines are for testing purposes. And they're failing. :-)

    Any help would be greatly appreciated. Thank you!

    David

    P.S. I'm using Drupal, and this is a node template. I hope that's not the problem, but just FYI.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    What is this statement supposed to do?[php] $flv = base_path() . 'files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd . '.flv';[/php]base_path() is not a PHP function, so how can I check if you correctly build the file path/name?

    And looking at the thread title, where is the fread() gone? Because that one is reported (by you) as giving the error.

    file_exists() only returns a true or a false, so that is all var_dump will return.

    Ronald

    Comment

    • bobzillaforever
      New Member
      • Mar 2008
      • 4

      #3
      Originally posted by ronverdonk
      What is this statement supposed to do?[php] $flv = base_path() . 'files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd . '.flv';[/php]base_path() is not a PHP function, so how can I check if you correctly build the file path/name?
      Apologies. base_path() is a Drupal function, returning (in this case) "/drupal-6/". I was trying to clean the irrelevant stuff from my code.
      Originally posted by ronverdonk
      And looking at the thread title, where is the fread() gone? Because that one is reported (by you) as giving the error.
      Same problem. I was trying to clean it up, and insodoing erased something important.
      [PHP]$test = '/sundays/files/sundays/' . $yy . '/' . '/' $mm '/' . $yymmdd . '.txt';[/PHP]
      Thank you, Ronald.

      David

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        You are welcome. See you next time.

        Ronald

        Comment

        • bobzillaforever
          New Member
          • Mar 2008
          • 4

          #5
          Originally posted by ronverdonk
          You are welcome. See you next time.

          Ronald
          Oops. To clarify, I haven't had any resolution yet. I will, however, continue working on this issue in the forums on Drupal's site, as I'm thinking that might be where my error starts. Thanks.

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            I am sorry. I had the idea that you knew where the problem was located and that you were able to fix it. Anyway, see you again soon (maybe).

            Ronald

            Comment

            • bobzillaforever
              New Member
              • Mar 2008
              • 4

              #7
              Issue solved. It ended up having nothing to do with Drupal. I was unaware of the different ways a document root could be delivered. And unaware of how to use fread(), so my method of error-checking was faulty. My main issue was trying to get file_exists() to work.

              I solved by changing:

              [PHP]$fileCheck_url = base_path() . '/files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd;
              //prints /drupal-6/files/sundays/2008/02/20080209[/PHP]To:

              [PHP]$fileCheck_url = $_SERVER['DOCUMENT_ROOT'] . base_path() . '/files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd;
              //prints C:/Apache/htdocs/drupal-6/files/sundays/2008/02/20080209[/PHP]That's working for me.

              To get fread() to work, I used the following code:

              [PHP] $fileCheck_url = $_SERVER['DOCUMENT_ROOT'] . base_path() . '/files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd;
              $fileCheck = array(
              'flv' => $fileCheck_url . '.flv',
              'wmv' => $fileCheck_url . '.wmv',
              'mp3' => $fileCheck_url . '.mp3',
              'txt' => $fileCheck_url . '.txt'
              );

              $handle = fopen($fileChec k['txt'], "r");
              $contents = fread($handle, filesize($fileC heck['txt']));
              fclose($handle) ;
              print $contents;[/PHP]Thanks again!

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                Glad you solved it in the end. See you soon.

                Ronald

                Comment

                Working...