Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP's fopen is terminally failing
    text
    copied!<p>Okay, I have GOT to be missing something totally rudimentary here. I have an extremely simple use of PHP's fopen function, but for some reason, it will not open the file no matter what I do.</p> <p>The odd part about this is that I use fopen in another function in the same script and it's working perfectly. I'm using the fclose in both functions. So, I know it's not a matter of a rogue file handle.</p> <p>I have confirmed the file's path and the existence of the target file also.</p> <p>I'm running the script at the command-line as root, so I know it's not apache that's the cause. And since I am running the script as root, I am fairly confident that permissions are not the issue.</p> <p>So, what on earth am I missing here?</p> <pre><code>function get_file_list() { $file = '/home/site/tmp/return_files_list.txt'; $fp = fopen($file, 'r') or die("Could not open file: /home/site/tmp/return_files_list.txt for reading.\n"); $files_list = array(); while($line = fgets($fp)) { $files_list[] = $line; } fclose($fp); return $files_list; } function num_records_in_file($filename) { $fp = fopen( $filename, 'r' ); # or die("Could not open file: $filename\n"); $counter = 0; if ($fp) { while (!feof( $fp )) { $line = fgets( $fp ); $arr = explode( '|', $line ); if (( ( $arr[0] != 'HDR' &amp;&amp; $arr[0] != 'TRL' ) &amp;&amp; $arr[0] != '' )) { ++$counter; continue; } } } fclose( $fp ); return $counter; } </code></pre> <p>As requested, here's both functions. The second function is passed an absolute path to the file. That is what I used to confirm that the file is there and that the path is correct.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload