Hi all,

I am having an error that many before me have had but none of the solutions have helped me.

I am using ob_start() to suppress the output and then using include to pull in a file which is dynamically built. However I keep getting the error

Failed to open stream. No such file or directory

php.net has a warning that this will occur on Apache based systems (which I'm using) however the workaround is not working. Also, using the absolute path to call the file also does not work.

I am using a Mac which I am unfamiliar with and wonder if it is a Mac issue. I don't have a Linux box available at this time to try it on.

PHP version is 5.2.12.

Any suggestions would be great.

Thanks.

    It seems that no one has anything to add.

    Following is the code that I am using where method getBufferedContent is the callback function:

    		private function getBufferedContent()
    		{
    			chdir( _DOC_ROOT );
    
    		include( _DOC_ROOT .'/views/forms/test.php' ) ;
    		$this->content = ob_get_contents();
    	}

    DOC_ROOT is defined as $SERVER['DOCUMENT_ROOT'] and the file definitely exists. Why can this system not find it? It seems that it should be very straight forward.

      Never mind. I have solved it.

      The actual line I had to include was:

      include( _DOC_ROOT .'/views/forms/test.php' ) or die( 'Unable to get form: '. _DOC_ROOT .'/views/forms/test.php' );

      But for some reason you cannot use the die() function after include() or require().

        Sure you can, as longas you understand how include and require works. Skipping parentheses around what you believe is the file name will help... Consider

        include ('file') . '.php';		# what would this include?
        include 'file' . '.php';		# what would this include?
        
        (include 'file') . 'php';		# what would this include?

        So yes, using or die would most certainly work

        (include 'file.php') or die ('file not included');
        echo 'file included';
        

        Which will of course still show warnings, such as "failed to open stream" if 'file.php' is not found. But the code does indeed work as expected.

        Have you tried to echo _DOC_ROOT .'/views/forms/test.php' to screen? What does it really contain?

          Write a Reply...