Set Attribute File/Image type, how?
Permalink
Hi All, I'm trying to set an attribute to a custom page type via a script but it seems like I'm missing something, to set the attribute of type image/file what do you need? the file name or the file id?
I already have the file in the file manager, I just need to update the file for a particular page.
Any help is greatly appreciated, thanks.
$attributes->setAttribute('product_image', 2); $attributes->setAttribute('product_image', 'name.jpg');
I already have the file in the file manager, I just need to update the file for a particular page.
Any help is greatly appreciated, thanks.
I'd think the file id, but Im not sure
Thanks, I tried that but no go, got the following error
"Fatal error: Call to a member function getFileID() on a non-object"
Any other ideas?
"Fatal error: Call to a member function getFileID() on a non-object"
Any other ideas?
It was giving you that error because it was expecting a file object in the save function - you need to first create a file object and then pass that in as your argument.
$fObj = File::getByID($fID); $attributes->setAttribute('product_image', $fObj);
Thanks hereNT, that did the trick!
Seems a bit weired to me that
did not work for me, but your solution does. I think they should be semantically equal.
$p->setAttribute('image', File::getByID($fid));
did not work for me, but your solution does. I think they should be semantically equal.
does anyone know how to get the id without the ID? let's say if I only know the image file name. how do I get the ID set the image attribute? I tried using File::getByHandle($imageName); but it didnt work.
Anyone? please :)