Jump to content

How do I POST file content to this web service? (almost have it with example)


ultrus

Recommended Posts

I'm messing with a web service that allows me to upload a photo through http to later be printed. They don't have any php examples, so I'm attempting my own. I'm getting close, but am not sure how to post the file content as raw data rather than a post variable.

 

Here's what they want:

 

POST /upload HTTP/1.0

Content-Type: image/jpg

Content-Length: xxx

 

... file content here ...

 

Here's what I have so far (with trouble area commented):

 

//settings
$file = "test.jpg";
$len = filesize($file);
$type = "image/jpg"; 
$fileContents = @readfile($file);
$toURL = "http://www.serviceurl.com/upload";

//init session	
$curlSession = curl_init($toURL);

//send options
curl_setopt($session, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_HTTPHEADERS,array("Content-Type: $type","Content-Length: $len"));
//#####################################
//!!!!! how do I add file contents? !!!
//#####################################

//recieve options
curl_setopt($curlSession, CURLOPT_HEADER, false); 
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true); 

//get response
$reply = curl_exec($curlSession); 

//close curl session
curl_close($curlSession);

echo $reply;

 

Any thoughts?  ???  I'll post if I find something first.

Do they have an example in another scripting language like perl? If so, post that and someone might be able to tell you how to do it in PHP.

 

BTW, what is a the service?

 

Ken

shot in the dark, but maybe if you create an image resource from your file with imagecreatefromjpeg and send the image resource... dunno what they are doing on their end, but you would normally have a resource from something like that function and then output it with imagejpeg as raw file

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.