Apache 2.4 PHP curl no status from mediaserver (on Windows 7)
<p>I have a script to upload an image to Hyves. When I use the script example online it works, but when I run it from my server, I get a no status error from mediaserver. I hope someone can help me because I've been struggling for a week now to make this work from my server. I have compared the upload URL from the working example with my own script and it is the same. I turned off my firewall etc. It didn't work either. It is a small image, 30Kb, so it isn't the size. As you can see in my code I tried several CURL options too.
Thanks.</p>

<p>My code is below:</p>

<pre><code>require("JSON.php");
$json = new Services_JSON();
$log = false;
$mediaUploadIp = stripslashes($_GET['mediaUploadIp']);
$mediaUploadToken = stripslashes(urldecode($_GET['getUploadtoken']));
echo "upload url: http://".$mediaUploadIp."/upload? token=".urlencode$mediaUploadToken)."&lt;br&gt;&lt;br&gt;";
$c = curl_init("http://".$mediaUploadIp."/upload?token=".urlencode($mediaUploadToken)."/");
$angle = 0;
$title = "Testupload";
$description = "Testdescription";
$latitude = "";
$longitude = "";
$filePath = "test.jpg";
curl_setopt(
  $c,
  CURLOPT_HTTPHEADER,
  array(
    'Content-Type: multipart/form-data',
    'Content-Type: image/jpg'
  )
);
curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SU    3.21; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POSTFIELDS, array("title"=&gt;$title, "angle"=&gt;$angle, "description"=&gt;$description, "file"=&gt;$filePath));
curl_setopt($c, CURLOPT_VERBOSE, true); // Display communication with server
//curl_setopt($c, CURLOPT_HEADER, 1);
//curl_setopt($c, CURLOPT_POSTFIELDS, $data);
//curl_setopt($c, CURLOPT_HTTPHEADER, $headers);//curl_setopt($c, CURLOPT_VERBOSE, 1);
//curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
//curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL);
//curl_setopt($c, CURLOPT_POST, true);
$response = curl_exec($c);
$r = var_dump($c);
print "&lt;pre&gt;\n";print_r(curl_getinfo($c));
// get error info
echo "\n\ncURL error number:" .curl_errno($c);
// print error info
echo "\n\ncURL error:" . curl_error($c);
print "&lt;/pre&gt;\n";
if(!curl_errno($c)) {
  $info = curl_getinfo($c);
  //echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}
if (!$response) {
  $http_code = curl_getinfo($c, CURLINFO_HTTP_CODE);
  curl_close($c); // make sure we closeany current curl sessions
  die($http_code.' Unable to connect to server. Please come back later.');
}
curl_close($c);
$loop = true;
$guard = 0;
while ($loop) {
  ++$guard;
  sleep(3);
  $c = curl_init("http://".$mediaUploadIp."/status?token=".urlencode($mediaUploadToken));
  curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
  $reply = $json-&gt;decode(curl_exec($c));
  echo curl_error($c);
  if($log) {
    echo "&lt;pre&gt;";
    print_r($reply);
    echo "&lt;/pre&gt;";
  }
  curl_close($c);
  $state = $reply-&gt;data-&gt;$mediaUploadToken;
  if (!isset($state[0]-&gt;currentstate)) {
    trigger_error("no status from mediaserver");
  }
  switch($state[0]-&gt;currentstate) {
    case "done":
      echo "current state: ".$state[0]-&gt;currentstate." -- &lt;br&gt;";
      echo "media_id: ".$state[0]-&gt;done-&gt;mediaid." is uploaded to &lt;a href='http://www.hyves.nl/profielbeheer/profielinfo/fotos/'&gt;all photos&lt;a/&gt; on your profile, you can now add this media to an album) \n";
      $loop = false;
      break;
    case "error":
      echo "Error: ".$state[0]-&gt;error-&gt;errormessage."&lt;br&gt;";
      $loop = false;
      break;
    default:
      echo "current state: ".$state[0]-&gt;currentstate." -- &lt;br&gt;";
      // we'll just continue
  }
  if ($guard &gt; 20) {
    echo "Takes too long\n";
    $loop=false;
  }
}
?&gt;
</code></pre>
