In my node.tpl.php file, 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.

      <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.

          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:

          $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($flv)) {
          // my code
           } else {
           echo '<p>file ' . $flv . ' doesn\'t exist.</p>'; }
           var_dump(file_exists($test));
          echo '<br />';
          fread($test, 8);

The last three lines are for testing purposes. And they're failing. :-)

Any help would be greatly appreciated. Thank you!

David

Comments

bobzillaforever’s picture

It was brought to my attention that I have a nasty typo in this post. fread() refers to "$test" which I didn't post.
$test = base_path() . 'files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd . '.flv';
Sorry about that!

bobzillaforever’s picture

Issue solved. 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:

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

To:

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

That's working for me.

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

      $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($fileCheck['txt'], "r");
      $contents = fread($handle, filesize($fileCheck['txt']));
      fclose($handle);
      print $contents;

Thanks.