cURL / Mailing Lists / curl-library / Single Mail

curl-library

cURL-PHP PUT problem

From: Mahendra Gayatri <mgayatri_at_SolutionSet.com>
Date: Fri, 4 Apr 2008 05:01:43 -0700

 
Hi,
I was trying to use PUT to place a file onto a server. The deal here was to set certain headers, which I am doing too. But still there seems to be a problem as I am getting a response from Server saying the Headers were not set properly.
Following is the code:
// EggName is the name of the new file to be PUT. Eggfile is the local file path
public function PutEgg($StorageURL, $StorageToken, $EggName, $Eggfile){
   $StorageToken = "Token: ".$StorageToken;
   
   // Here I am Hashing the file to MD5, once that done I have to send that in Header
   $fileContent = file_get_contents($Eggfile);
   $mdData = md5($fileContent);
   echo 'file content = '.$fileContent.' : '.$mdData;
   $ETag = 'ETag: '.$mdData;
   $fileSize = filesize($Eggfile);
   $ContentLength = 'Content-Length: '.$fileSize;
   
   // Here I am forming the Header
   $header = array($StorageToken, $ETag, $ContentLength);
   $ch = curl_init();
   
   // set URL and other appropriate options
   curl_setopt($ch, CURLOPT_URL, trim($StorageURL)."/".$EggName);
   $fp = fopen ($Eggfile, "r");
   curl_setopt($ch, CURLOPT_INFILE, $fp);
   curl_setopt($ch, CURLOPT_INFILESIZE, $fileSize);
   curl_setopt($ch, CURLOPT_PUT, TRUE);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
   curl_setopt($ch, CURLOPT_HEADER, 1);
   
   $result = curl_exec($ch);
   
  }
Server Response:---
HTTP/1.1 412 Precondition Failed
Date: Fri, 04 Apr 2008 09:56:24 GMT
Server: Apache/2.2.3 (Debian) mod_python/3.2.10 Python/2.4.4
Content-Length: 0
Content-Type: text/plain; charset=UTF-8
------------------------------------------------------------
Any light people?
Received on 2008-04-04