Simple PHP upload

NygrenNygren Registered Users Posts: 17 Big grins
Hey guys!

I'm looking for a simple way to let a php script on my web site upload an image to smugmug and set the smugmug filename of the image. I don't need to send captions or anything else. Just set the filename and upload it via php to Smugmug.

Since I'm not a great php programmer, would anybody care to provide a simple little php code snippet for me to use?

Thanks a bunch!

Anders

Comments

  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited April 24, 2011
    G'day Anders,

    Something like this should work...

    [php]
    <?php
    // create a new cURL resource
    $ch = curl_init();
    $file = fopen($path, 'r');

    $header = array(
    "X-Smug-AlbumID: {$albumId}",
    "X-Smug-FileName: {$filename}",
    "X-Smug-SessionID: {$sessionId}"
    );

    curl_setopt($ch, CURLOPT_URL, "http://upload.smugmug.com/{$filename}");
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_POST, false);
    curl_setopt($ch, CURLOPT_PUT, true);
    curl_setopt($ch, CURLOPT_INFILE, $file);
    #curl_setopt($ch, CURLOPT_INFILESIZE, $filesize); # it's a good idea to send this as well as Content-MD5 for error checking
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);

    fclose($file);
    curl_close($ch);
    ?>
    [/php]

    Cheers,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • NygrenNygren Registered Users Posts: 17 Big grins
    edited April 25, 2011
    Thank you so much! I will try this out ASAP and let you know how it goes!

    clap.gif
  • NygrenNygren Registered Users Posts: 17 Big grins
    edited April 30, 2011
    Hmm.. a bit embarrassing to ask this, but where to I get this "SessionID" to pass along to the server? Wouldnt it be possible to authenticate with my usual username and password?
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited April 30, 2011
Sign In or Register to comment.