0
votes

I am trying to upload multiple photos into a photoset post to Tumblr. I am using PHP to connect to Tumblr and authenticate. I can post individual photos and video but can't seem to figure out photosets. There are other posts on Stack that help other languages except for PHP.

I have a directory of photos. I get the contents of those file and put them into an array using scandir. But when I try to post that array to Tumblr, it doesn't work.

$scanned_directory = array_diff(scandir($directory), array('..', '.'));

$connection->post("blog/$hostname/post", array('type' => 'photo', 'state' => $dest, 'link' => $sourceurl, 'source' => $sourceurl, 'caption' => $caption, 'tags' => $tags , 'data' => $scanned_directory));

What am I doing wrong?

Thanks for the help!

1

1 Answers

2
votes

I think you should iterate the $scanned_directory variable and make sure you don't submit the just the path and filename to the Tumblr API, but the actual contents of your image file with file_get_contents(), a working example would look probably something like this:

foreach($scanned_directory as $filename){
    $data[] = file_get_contents($directory.'/'.$filename);
}
$connection->post("blog/$hostname/post", array('type' => 'photo', 'state' => $dest, 'link' => $sourceurl, 'source' => $sourceurl, 'caption' => $caption, 'tags' => $tags , 'data' => $data));

That should likely do the trick, just make sure the $directory variable is actually an absolute path to your image directory (e.g. '/var/www/myhost.tld/public/images/photoset')