Cant get this image upload to work...

I’ve done this a dozen times in the past without problem. Now for some reason I can’t save a screenshot to my server even after adding all permissions to everyone (read/write) on folders I’m trying to work with.

I even took the example off the Unity docs for .EncodeToPNG() http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.EncodeToPNG.html

and can’t get it to work either, without even changing anything other than the url to send it to…

I’ve tried various versions of php to save the file, and in the past it’s worked fine on the same server.

I customized the php from this page at the bottom “saving the uploaded file” as well as ones shown to be working as answers in unity answers/forums…

Here’s the php:

<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
 ($_FILES["file"]["size"] < 20000000)
 in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "
";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "
";
    echo "Type: " . $_FILES["file"]["type"] . "
";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB
";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

And the screenshot code other than the .encodetopng() example:

                                        //SCREENSHOT ON PC
					Application.CaptureScreenshot(screenshotFilename);		
					yield return new WaitForSeconds(0.1f);
					byte[] bytes = File.ReadAllBytes( screenshotFilename );					
					Texture2D tx = new Texture2D(Screen.width,Screen.height,TextureFormat.ARGB32, false);
					tx.LoadImage(bytes);
				
					GameObject imgplane = GameObject.Find("imgDisplay") as GameObject;
					imgplane.renderer.material.mainTexture = tx;
			
					// Create a Web Form
					WWWForm form = new WWWForm();
					form.AddField("frameCount", Time.frameCount.ToString());
					form.AddBinaryData("file",  bytes, "0001.png", "image/png");
//also tried  form.AddBinaryData("file",  tx.EncodeToPNG(), "0001.png", "image/png");

Any ideas? I’ve tried a number of variations, checked permissions, etc…

Does your web server log a connection request? (Maybe the connection to the server isn’t working.)

If the connection is made, what code path is used in the PHP? Add some more echo statements if you need to.