简体   繁体   中英

PHP fopen/fwrite problem on IIS7

I am running PHP5 on IIS7 on Windows Server 2008 R2. Check out the below code which writes a string received via a POST request parameter into an XML file.

<?php
$temp = "";
if($_SERVER['REQUEST_METHOD']=="POST"){
    if($_POST["operation"]=="saveLevels"){
        $fileHandle = fopen("c:\\inetpub\\wwwroot\\test\\xml\\levels.xml", 'w');
        fwrite($fileHandle, stripslashes($_POST["xmlString"]));
        fclose($fileHandle);
        $temp = "success";
    }elseif($_POST["operation"]=="saveRules"){
        $fileHandle = fopen("c:\\inetpub\\wwwroot\\test\\xml\\rules.xml", 'w');
        fwrite($fileHandle, stripslashes($_POST["xmlString"]));
        fclose($fileHandle);
        $temp = "success";
    }
}

When I make a POST request to invoke this code, the application pool owning/hosting the site containing php files, stops (due to some fatal errors, as it writes in event viewer) and then IIS keeps responding with HTTP503 after that. Now, I have given proper permissions to IUSR and IISUSRS on that (test/xml) directory. Those two XML files are not already existing, I have also tried the code when an XML file is already present but; it behaved the same way. What's wrong with that php code? I have tried it on a linux-box and it behaved as expected.

edit: I have tried various different versions of this code and came up with this result: the fopen call when awaken by a POST request, allways returns FALSE or sometimes NULL, and causes the Application Pool of itself to stop. The exact same code, works OK with a GET request, with exact same parameters. So; I dont know what the problem is but; for the time I'm just going to use GET requests for this operation.

Can you var_dump( $fileHandle) for both options, to show us what it has. I notice you're just assuming the file is opened, rather than checking the value (if it's FALSE the fwrite will fail)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM