上传文件错误到IIS7+PHP服务器

本文关键字:IIS7+PHP 服务器 错误 文件 | 更新日期: 2023-09-27 17:57:49

我有IIS7在Windows Server 2008 R2上运行,带有PHP 5.4。我创建了一个使用SSL加密的网站,使用上传和下载文件的PHP脚本。我还使用Visual Studio 2012(C#)创建了一个客户端应用程序,该应用程序使用WebClient对象来执行上载/下载。下载效果很好。但是,当我尝试上传文件(使用WebClient)时,会出现WebException:

Message: The remote server returned an error: (500) Internal Server Error.
Status: System.Net.WebExceptionStatus.ProtocolError
InnerException: null;

PHP上传脚本当前为空(文件应上传到服务器上的临时目录,然后自动删除)。我应该补充一点,我可以在浏览器中运行PHP脚本,而不会出现任何错误(即不上传任何内容)。起初,我认为IIS服务帐户可能无法访问临时目录,但添加显式权限并不能解决问题。有什么想法吗?

我的C#代码如下:

public static void UploadFile(Uri uri)
{
    try
    {
        using (WebClient client = new WebClient())
        {
            // Ignore SSL warnings due to unsigned certificate.
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
            client.Credentials = CredentialCache.DefaultNetworkCredentials;
            // Get a path/name of a new temporary file.
            String tempFile = Path.GetTempFileName();
            // Create a 1KB temporary file.
            using (var fileStream = new FileStream(tempFile, FileMode.Create, FileAccess.Write))
            {
                fileStream.SetLength(1024);
            }
            // Upload the file to the server.
            client.UploadFile(uri, tempFile);
            // Delete temporary file.
            File.Delete(tempFile);
        }
    }
    catch (WebException ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

更新1-IIS日志文件

2013-02-04 17:05:05 155.14.123.53 POST /Archive/uploadTest.php - 443 - 155.14.123.208 - 401 2 5 0
2013-02-04 17:05:05 155.14.123.53 POST /Archive/uploadTest.php - 443 HYPER'JOHNSD 155.14.123.208 - 500 0 0 15

上传文件错误到IIS7+PHP服务器

哦,天哪。。。我真的觉得自己很笨。这是临时文件夹的权限问题。我确实将IIS服务帐户添加到临时文件夹的安全设置中,但我忘记添加权限=P