简体   繁体   中英

Upload File Error to IIS7 + PHP Server

I have IIS7 running on Windows Server 2008 R2 with PHP 5.4. I have created a website with SSL encryption with PHP scripts that upload and download files. I have also created a client application using Visual Studio 2012 (C#) that uses the WebClient object to perform the uploads/downloads. The downloads work perfectly. However, when I try to upload a file (using WebClient), a WebException occurs:

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

The PHP upload script is currently blank (the file should be uploaded to the temporary directory on the server and then automatically deleted). I should add that I'm able to run the PHP script in my browser without any errors (ie not uploading anything). At first I thought that maybe the IIS service account didn't have access to the temporary directory, but adding explicit permission didn't solve the problem. Any ideas?

My C# code is as follows:

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());

    }

}

Update 1 - IIS Log File

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

Oh boy...I really feel stupid. It was a permissions issue on the temp folder. I did add the IIS service account to the temp folder's security settings, but I forgot to add permissions. =P

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