Main
Latest
- Sun Java 6 on Ubuntu Jaunty
- Zoopy PHP CLI Upload
- Modern Spam
- Afrihost Capping #fail
- Muti Facebook Source Code
- Muti Facebook Page
- Temperature Management
- Muti Web Hook Support
- hCard parsing with lxml in Python
- Python Command Subshells
Archives
- June 2004
- July 2004
- August 2004
- September 2004
- October 2004
- November 2004
- December 2004
- January 2005
- February 2005
- March 2005
- April 2005
- May 2005
- June 2005
- July 2005
- August 2005
- September 2005
- October 2005
- November 2005
- December 2005
- January 2006
- February 2006
- March 2006
- April 2006
- May 2006
- June 2006
- July 2006
- August 2006
- September 2006
- November 2006
- December 2006
- January 2007
- February 2007
- March 2007
- April 2007
- May 2007
- June 2007
- July 2007
- August 2007
- September 2007
- October 2007
- November 2007
- December 2007
- January 2008
- February 2008
- March 2008
- April 2008
- May 2008
- June 2008
- July 2008
- August 2008
- September 2008
- October 2008
- November 2008
- December 2008
- January 2009
- February 2009
- March 2009
- April 2009
- May 2009
- June 2009
- July 2009
- August 2009
- September 2009
- October 2009
- November 2009
Sun Java 6 on Ubuntu Jaunty
Yes I know I am supposed to be upgrading to Karmic; I already downloaded the ISO images but I don't have the time this week or next.
Since I am on a liberal local cap, I thought I might as well just install all the Java 6 packages except the documentation, as that needs to be handled separately.
sudo aptitude install sun-java6-? sun-java6-doc:
Then you have to make sure you have the JAVA_HOME environment variable set up correctly:
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.16
(Just check that dir, it might be a bit different on your system.)
Zoopy PHP CLI Upload
I recently had quite a number of pictures I wanted to upload to Zoopy and was looking for an easier way to upload an entire directly of images straight from the command line. I ended up writing the following PHP script and making use of their RESTful API which ended up working fairly nicely.
#!/usr/bin/php
<?php
$username = 'charlvn';
$password = 'test123';
if (!isset($_SERVER['argv'][1])) {
echo "Please enter a title.\n";
exit(1);
}
$dir = new DirectoryIterator(getcwd());
$userpwd = sprintf('%s:%s', rawurlencode($username), rawurlencode($password));
foreach ($dir as $item) {
if ($item->isFile()) {
echo sprintf('Uploading %s... ', $item->getBasename());
$params = array();
$params['file'] = '@' . $item->getRealPath();
$params['title'] = $_SERVER['argv'][1];
if (isset($_SERVER['argv'][2])) {
$params['tags'] = $_SERVER['argv'][2];
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, 'http://api.zoopy.com/rest/media/upload.json');
curl_setopt($curl, CURLOPT_USERPWD, $userpwd);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($curl);
if (is_string($response)) {
$data = json_decode($response, true);
if ($data['result'] == 'success') {
echo "Done\n";
} elseif ($data['result'] == 'error') {
echo sprintf("Failed\n%s\n%s\n", $data['content']['title'], $data['content']['message']);
exit(1);
} else {
echo sprintf("Failed\nUnknown response from server:\n%s\n", $response);
exit(1);
}
} else {
echo "Failed\nAn unknown error occurred.\n";
exit(1);
}
}
}
Copyright © 2004-2009 Charl van Niekerk. All articles are released under the Creative Commons Attribution 2.5 South Africa licence, unless where otherwise stated.

