0

I am getting the following error when trying to echo the HTML contents of a file inside a wordpress plugin folder.

Warning: filesize() [function.filesize]: stat failed for http://bestideabox.com/wp-content/plugins/jww-namechord/ includes/template-files/single-form.html in /home/bestidea/public_html/wp-content/plugins/ jww-namechord/includes/core.php on line 44

Here is the function that reads the file:

return jww_display_file( 
        plugins_url( 'template-files/'.$template.'.html',__FILE__ ) 
    );


        function jww_display_file( $fileToRead ){

            //Open the file and read it
            $handle = fopen( $fileToRead, "r" );
            $contents = fread( $handle, filesize( $fileToRead ) );
            fclose( $handle );

            //return it
            return $contents;
        }           

I am at a complete loss. Any Help would be appreciated.


Not sure how to mark this as an answer, but thanks to DaveRandom I have a solution:

The http:// wrapper does not support stat(). You cannot filesize() a HTTP URL. You can use the Content-Length: header of the response if the server returns one, but you actually don't need to here. Just replace the entire body of that function with return file_get_contents($fileToRead); and you're set. – DaveRandom

To those who marked as duplicate. You can see from answer it is not the same issue. Thanks guys for all your help!

Owen Pauling
  • 11,349
  • 20
  • 53
  • 64
  • This is what is inside the HTML file -

    Baby Naming 101 - No "Y" support

    Enter Name:
    Enter ID:
    – user2300933 Apr 19 '13 at 23:17
  • 1
    What's the value of `fileToRead`? If it's a URL, not a regular filename, `filesize()` doesn't work. – Barmar Apr 19 '13 at 23:18
  • Don't put code in comments, edit your question. – Barmar Apr 19 '13 at 23:19
  • And it doesn't matter what's in the HTML file. – Barmar Apr 19 '13 at 23:19
  • 2
    The [`http://`](http://php.net/wrappers.http) wrapper does not support `stat()`. You cannot `filesize()` a HTTP URL. You can use the `Content-Length:` header of the response if the server returns one, but you actually don't need to here. Just replace the entire body of that function with [`return file_get_contents($fileToRead);`](http://php.net/file-get-contents) and you're set. – DaveRandom Apr 19 '13 at 23:21
  • @Dave.. make this an answer – Zak Apr 19 '13 at 23:34
  • Dave. You are the man! that worked great!!! – user2300933 Apr 20 '13 at 00:11

0 Answers0