Created
August 31, 2012 03:01
-
-
Save ianwremmel/3548403 to your computer and use it in GitHub Desktop.
www.ianwremmel.com: PUTting PHP to Restful APIs (Like CouchDB) as JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ($collection as $id => $data) { | |
$handle = fopen(FILENAME, 'w'); | |
$filesize = fwrite($handle, json_encode($data)) | |
fclose($handle); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, SERVER_URL . '/' . DATABASE . '/' . $id); | |
curl_setopt($ch, CURLOPT_PUT, TRUE); | |
$handle = fopen(FILENAME, 'r'); | |
curl_setopt($ch, CURLOPT_INFILE, $handle); | |
curl_setopt($ch, CURLOPT_INFILESIZE, $filesize); | |
curl_exec($ch); | |
curl_close($ch); | |
fclose($handle); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ($collection as $id => $data) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, SERVER_URL . '/' . DATABASE . '/' . $id); | |
curl_setopt($ch, CURLOPT_PUT, TRUE); | |
curl_setopt($ch, CURLOPT_INFILE, $data); | |
curl_exec($ch); | |
curl_close($ch); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ($collection as $id => $data) { | |
$handle = tmpfile | |
$filesize = fwrite($handle, json_encode($data)) - 2; | |
fseek($handle, 1); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, SERVER_URL . '/' . DATABASE . '/' . $id); | |
curl_setopt($ch, CURLOPT_PUT, TRUE); | |
curl_setopt($ch, CURLOPT_INFILE, $handle); | |
curl_setopt($ch, CURLOPT_INFILESIZE, $filesize); | |
curl_exec($ch); | |
curl_close($ch); | |
fclose($handle); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ($collection as $id => $data) { | |
$handle = tmpfile | |
$filesize = fwrite($handle, json_encode($data)) | |
rewind($handle); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, SERVER_URL . '/' . DATABASE . '/' . $id); | |
curl_setopt($ch, CURLOPT_PUT, TRUE); | |
curl_setopt($ch, CURLOPT_INFILE, $handle); | |
curl_setopt($ch, CURLOPT_INFILESIZE, $filesize); | |
curl_exec($ch); | |
curl_close($ch); | |
fclose($handle); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ($collection as $id => $data) { | |
$handle = tmpfile | |
$data = json_encode($data)); | |
$length = strlen($data) | |
$data = substr(1, $data, $length) - 2; | |
$filesize = fwrite($handle, $data) | |
rewind($handle); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, SERVER_URL . '/' . DATABASE . '/' . $id); | |
curl_setopt($ch, CURLOPT_PUT, TRUE); | |
curl_setopt($ch, CURLOPT_INFILE, $handle); | |
curl_setopt($ch, CURLOPT_INFILESIZE, $filesize); | |
curl_exec($ch); | |
curl_close($ch); | |
fclose($handle); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment