views:

79

answers:

2

Hi,

I have XAMPP installed on a windows 2000 server. everything is working great except the PHP fopen function. I can neither create nor open files with it. the strange thing is that i can include/require/file_get_contents/other file related functions; also fopen does not generate any errors or notices it just returns NULL.

I have gone as far as to grant full control of the file and all enclosing folders to everybody but i still get NULL instead of a file pointer.

I have tried this on php 5.2.9, 5.2.13, and 5.3.1 with the same effect. i have gone through the php.ini file looking for something that is breaking it; i have even tried deleting and using the basic ini file from a linux box where fopen is working and still nothing.

I know i have to restart apache after changing my ini and all that and have been (I have even restarted the server) so thats not it.

I am at this poing assuming it is an apache configuration issue somehow, tomorrow im going to run a test through php-cli to make sure.

I really don't want to bruise my head anymore over this can some apache/php wizard come to my aid?


Hi guys,

thanks for the responses. you are right is is not any config problem. the problem has to be with one of my dlls or one of my included files. I just tried the same code that isn't working in a new file without any include and i disabled my custom libraries and it worked.

for the record here is what I was doing that wasn't working:

$test_file = 'c:\\test.csv';//everybody has full control. is very large.
    if(file_exists($test_file) && is_readable($test_file)){
        $fp = fopen($test_file, 'r');
        echo var_export($fp, true);//outputs NULL. on my linux box this is a number.
        if($fp !== false){
            //do the work
            fread($fp, 10);//throws the error that $fp is not a valid file handle
        }
    }

something that i am including must be breaking fopen somehow. works as expected in new file with no includes.

A: 

So we're to assume you're using this kind of code:

$fp = fopen( "my_file.txt", "r" );
$contents = fread($fp, filesize( "my_file.txt" ) );
fclose($fp);

Am I to assume the filesize() function returns null? Also try the stat($filename) function to see if you get a relatively complete array.

Let me know your results.

seacode
A: 

Hi guys,

thanks for the responses. you are right is is not any config problem. the problem has to be with one of my dlls or one of my included files. I just tried the same code that isn't working in a new file without any include and i disabled my custom libraries and it worked.

for the record here is what I was doing that wasn't working:

$test_file = 'c:\\test.csv';//everybody has full control. is very large.
    if(file_exists($test_file) && is_readable($test_file)){
        $fp = fopen($test_file, 'r');
        echo var_export($fp, true);//outputs NULL. on my linux box this is a number.
        if($fp !== false){
            //do the work
            fread($fp, 10);//throws the error that $fp is not a valid file handle
        }
    }

something that i am including must be breaking fopen somehow. works as expected in new file with no includes.

brad allred
You should update the question, not post the update as an answer.
Tim Lytle