Archive

Archive for the ‘apple’ Category

Getting Package HTTP_WebDAV_Client to Upload a File to an iDisk

March 26th, 2010 admin No comments

There is a PHP Pear Package called HTTP_WebDAV_Client which allows PHP to access a WebDav disk (like an iDisk!)

The following is the typical example posted to several forums which does NOT work to upload a file:

$local_path = 'local/filepath';
$remote_path = "webdavs://idisk.me.com/username/path/tofile";
$mode = 'w';
$options = array();
$opend_path = array();
$webdav_client = new HTTP_WebDAV_Client_Stream();
$status = $webdav_client->stream_open( $remote_path, $mode, $options, $opend_path );
if ( $status === false )
{
error_log( 'stream_open failed' );
exit;
}
$handle = fopen( $local_path, 'rb' );
$contents = fread( $handle, filesize( $local_path ) );
fclose( $handle );
$status = $webdav_client->stream_write( $contents );
if ( $status === false ) {
error_log( 'stream_write failed' );
exit;
}
$webdav_client->stream_close();

This will fail every time.  Firstly there is no way within the package to set the username and password which are essential to connect to a disk with authentication.  Secondly the stream_open function attempts to check WebDav options on the (not yet existent) file you wish to upload.  While it IS typically bad manners to simply run on into a package and edit stuff willy nilly it is sort of necessary in this case as the author has dropped off the face of the planet, the package is not fully functional, and no one has picked up the project.  (No I don’t plan to pick it up either I have enough to do thanks).

Thus to get it working I did 3 things:

1. I added a ‘set_user’ function to the Stream.php found within the package.  You should be able with very very basic PHP skills figure out how to do this.

2. I added a ‘set_password’ function to the Stream.php found within the package.  You should be able with very very basic PHP skills figure out how to do this.

3. I commented out ‘if (!$this->_check_options())  return false;’ in the stream_open function.

The fixed client code is thus:


$local_path = 'local/filepath';
$remote_path = "webdavs://idisk.me.com/username/path/tofile";
$mode = 'w';
$options = array();
$opend_path = array();
$webdav_client = new HTTP_WebDAV_Client_Stream();
$webdav_client->set_user('username');
$webdav_client->set_password('password');
$status = $webdav_client->stream_open( $remote_path, $mode, $options, $opend_path );
if ( $status === false )
{
error_log( 'stream_open failed' );
exit;
}
$handle = fopen( $local_path, 'rb' );
$contents = fread( $handle, filesize( $local_path ) );
fclose( $handle );
$status = $webdav_client->stream_write( $contents );
if ( $status === false ) {
error_log( 'stream_write failed' );
exit;
}
$webdav_client->stream_close();

This should work great.  Feel free to leave a comment or shoot me an email if this solution doesn’t do the trick for you!
Categories: PHP, Pear, Programming, Rants, Tips, WebDav, apple Tags: , , ,

Access Your Idisk using Perl

March 22nd, 2010 admin No comments

Hey all,

It took me a while to figure this out so I figured I’d pass it along.

I wanted to keep an offsite backup of some files on my MobileMe iDisk.

iDisk Uses the WebDav protocol so you can use this to access the disk.

There is a great Perl Module that let’s you accomplish this called PerlDav or HTTP::Dav

Just go to CPAN at the command line and type ‘make install HTTP::Dav’ or install it in the Perl Modules section if you’re working on a CPanel server.

Then just follow these steps to upload a file:
use HTTP::Dav;
$idisk = new HTTP::DAV;
$url = "https://idisk.me.com/YOURMOBILEMEUSERNAME/Documents";

$idisk->credentials( -user=>"YOURMOBILEMEUSERNAME",-pass =>"YOURMOBILEMEPASSWORD", -url =>$url);

$idisk->open( -url=>"$url" ) or die("Couldn't open $url: " .$d->message . "\n");

if ( $d->put( -local => "trs.sql", -url => $url ) )
{
print "Uploaded File\n";
}
else
{
print "Upload Failed\n";
}

Categories: Perl, Programming, Tips, apple Tags: , , ,

Was I ever that condescending?

March 10th, 2010 admin No comments

When Apple first opened their Crossgates Mall store I was one of the sales folks.  (Been there done that and I wear the shirt when I do laundry since I am contractually forbidden from wearing it elsewhere…)  Recently I stopped down there to have my (second!) MacBook power supply replaced.  I happened to ask a sales guy (not even a Mac genius guy) for help and he gladly started to swap it out.  I commented ‘Is this one any less likely to fray’, and he helpfully offered a few tips on it (including not really).  Apparently there’s stuff you can do involving looping the ends (fear not I’ve a MacRelations tutorial in mind).  Then when looking up my serial number he pointed out you DO NOT have to launch full on System profiler for a number.  Just click a few times at “About this Mac” and it cycles.

Maybe I’m bitter that I didn’t already know that but there was still a tad bit of “hey thanks by the way what do you think about the IPHONE APP I WROTE LAST NIGHT there”.

Ta think.  Told by a sales guy secret Mac tips.  I AM getting old. :(

Categories: Rants, apple, macintosh Tags:

Note

August 29th, 2009 admin No comments

I have been working on restoring all the old articles I wrote for Mac Relations to the site. If you remember any articles that you liked that aren’t there let me know. It is difficult to port them into WordPress from the old CMS but ideally I want everything that was ever there back (especially of course your favorites).

Categories: apple, articles, macintosh Tags: