ultrus Posted February 16, 2009 Share Posted February 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145415-how-do-i-post-file-content-to-this-web-service-almost-have-it-with-example/ Share on other sites More sharing options...
kenrbnsn Posted February 16, 2009 Share Posted February 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145415-how-do-i-post-file-content-to-this-web-service-almost-have-it-with-example/#findComment-763371 Share on other sites More sharing options...
.josh Posted February 16, 2009 Share Posted February 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145415-how-do-i-post-file-content-to-this-web-service-almost-have-it-with-example/#findComment-763372 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.