Simple PHP upload
Nygren
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
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
0
Comments
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
SmugMug API Developer
My Photos
SmugMug API Developer
My Photos