Martijn Geerts Posted July 18, 2012 Share Posted July 18, 2012 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 More sharing options...
Martijn Geerts Posted July 18, 2012 Author Share Posted July 18, 2012 It took a while, but I found the sulution: foreach($u->execute() as $key => $filename) { $page->images->add($filename); $page->images->eq($key)->description = 'what you want to say about the image'; } 1 Link to comment Share on other sites More sharing options...
Soma Posted July 18, 2012 Share Posted July 18, 2012 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 More sharing options...
Martijn Geerts Posted July 18, 2012 Author Share Posted July 18, 2012 lol, I'll take yours up in my code as reference, btw your's is easier to understand. Link to comment Share on other sites More sharing options...
Soma Posted July 18, 2012 Share Posted July 18, 2012 Just made a little test and changed code to add setOutputFormatting to false. This is required to get it to work. 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted July 18, 2012 Author Share Posted July 18, 2012 Actually in the real scenario the image is saved to in an other "parent", that parent & children doesn't have to render at all. For the forum it is good to have a complete working version of the actual page. Link to comment Share on other sites More sharing options...
ryan Posted July 19, 2012 Share Posted July 19, 2012 You should also be able to grab the last image and add the description to it: $page->images->add($filename); $page->images->last()->description = "description"; 8 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now