Page 1 of 1

file_get_contents() not working in IE

Posted: Mon Jun 14, 2010 3:05 pm
by dimxasnewfrozen
I have the following script:

Code: Select all

<?php 
$file 	= $_GET["selected_file"];
$filestring =  file_get_contents($file);
$filearray = explode("<br/>", $filestring);

    while (list($var, $val) = each($filearray)) {
        ++$var;
        $val = trim($val);
        print "Line $var: $val<br />";
    }

?>
This works wonderfully in firefox but displays nothing in IE. Is there a known issue with IE or is there something wrong with the script?

Re: file_get_contents() not working in IE

Posted: Mon Jun 14, 2010 3:13 pm
by flying_circus
PHP methods are not affected by the client browser. They are all run on the server side and do not care who or what requested the data.

Try outputting the value of $_GET['selected_file'] to make sure the values are identical on both IE and firefox. You should also check for file existence before accessing the file, try using file_exists(). You should also validate your input, preferably a white list of allowed files, else you might find your program is misused.

Re: file_get_contents() not working in IE

Posted: Mon Jun 14, 2010 3:51 pm
by dimxasnewfrozen
Right. I'm not worried about the security aspect of it yet.

It's actually bombing out on an ajax call I'm making (client side). I'm sending the contents of the file to a html textarea box which won't properly display in IE.

I'm not sure why IE is so picking when it comes to ajax/php calls.