Skip to content

Instantly share code, notes, and snippets.

@kawing-ho
Last active October 6, 2018 10:45
Show Gist options
  • Save kawing-ho/942e4aba4d28a0c34654d55a41060341 to your computer and use it in GitHub Desktop.
Save kawing-ho/942e4aba4d28a0c34654d55a41060341 to your computer and use it in GitHub Desktop.
Arguments: [Path to an image file]      Returns: [ URL to image ]
#!/usr/bin/php
<?php /* install php and php-curl */
if($argc != 2) {
fwrite(STDERR, "Usage: ".$argv[0]." <path to image>\n");
die();
}
$image = $argv[1];
if(! file_exists($image)) { fwrite(STDERR, "Not an image!\n"); die(); }
$ch = curl_init('https://vgy.me/upload');
$file = new CURLFile($image, 'application/octet-stream', 'test.png');
$data = array('file' => $file, 'title' => 'Test Upload', 'description' => 'yo');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
$array = json_decode($result, true);
if($array['error'] == 1) {
fwrite(STDERR, print_r($array));
} else {
// assume the upload was successful
print($array['image']);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment