简体   繁体   English

IIS7上的PHP fopen / fwrite问题

[英]PHP fopen/fwrite problem on IIS7

I am running PHP5 on IIS7 on Windows Server 2008 R2. 我在Windows Server 2008 R2的IIS7上运行PHP5。 Check out the below code which writes a string received via a POST request parameter into an XML file. 检出以下代码,该代码将通过POST请求参数接收的字符串写入XML文件。

<?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. 当我发出POST请求以调用此代码时,拥有/托管包含php文件的站点的应用程序池将停止(由于在事件查看器中写入的某些致命错误),然后IIS继续以HTTP503进行响应。 Now, I have given proper permissions to IUSR and IISUSRS on that (test/xml) directory. 现在,我已经对该目录(test / xml)授予了IUSR和IISUSRS适当的权限。 Those two XML files are not already existing, I have also tried the code when an XML file is already present but; 这两个XML文件尚不存在,当一个XML文件已经存在但我也尝试过该代码; it behaved the same way. 它的行为方式相同。 What's wrong with that php code? 那php代码怎么了? I have tried it on a linux-box and it behaved as expected. 我已经在linux-box上尝试过它,并且表现出预期的效果。

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. 编辑:我尝试过此代码的各种不同版本,并得出以下结果:fopen调用在被POST请求唤醒时始终返回FALSE或有时为NULL,并导致自身的应用程序池停止。 The exact same code, works OK with a GET request, with exact same parameters. 完全相同的代码对于具有相同参数的GET请求可以正常工作。 So; 所以; I dont know what the problem is but; 我不知道是什么问题,但是; for the time I'm just going to use GET requests for this operation. 目前,我仅将GET请求用于此操作。

Can you var_dump( $fileHandle) for both options, to show us what it has. 您能否同时使用var_dump($ fileHandle)来向我们展示它的功能。 I notice you're just assuming the file is opened, rather than checking the value (if it's FALSE the fwrite will fail) 我注意到您只是假设文件已打开,而不是检查值(如果为FALSE,则fwrite将会失败)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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