Jump to content

Setting image description with multiple image upload.


Martijn Geerts
 Share

Recommended Posts

Hello, I don't know how to set the description when uploading multiple images through the api.

So far images get uploaded nicely.


// instantiate the class and give it the name of the HTML field
$u = new WireUpload('uploads');

// tell it to only accept 5 files
$u->setMaxFiles(5);

// tell it to rename rather than overwrite existing files
$u->setOverwrite(false);

// have it put the files in their final destination. this should be okay since
// the WireUpload class will only create PW compatible filenames
$u->setDestinationPath($page->images->path);

// tell it what extensions to expect
$u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png'));

// execute() returns an array, so we'll foreach() it.
foreach($u->execute() as $filename) {
$page->images->add($filename);
}

// save the page
$page->save();

Link to comment
Share on other sites

How about

foreach($u->execute() as $filename) {

$img = $page->images->add($filename);

$img->description = "what you want to say about the image";

}

Edit: guess not. :) But it should also be possible to create a pagefile and add description before adding.

$page->setOutputFormatting(false); // or $page->of(false);
foreach($u->execute() as $filename) {
 $img = new Pageimage($page->images, $filename);
 $img->description = "what you want";
 $page->images->add($img);
}
$page->save();
$page->setOutputFormatting(true); // or $page->of(true);

Not tested but should work. I'm sure Ryan will come up with something else. But the solution you found is totally valid and also nice.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...