felixthecat Posted December 10, 2018 Share Posted December 10, 2018 Hello, What is the correct way to add an manually created file to an existing imagefield. The new created file is in the same Folder where the page stores the files. Here what i tried. Runs without errors but doesnt add the file to the imagefield: // image_ok.jpg is the file which is stored in the imagefield // image_new.jpg is the manually created file and should be added to the imagefield of image_ok.jpg $pagefiles = $imageOK->pagefiles; $pagefiles->add('image_new.jpg' ); $page = $imageOK->page; $page->of(false); $page->save($pagefiles->name); What is wrong? Thanks. Link to comment Share on other sites More sharing options...
Robin S Posted December 10, 2018 Share Posted December 10, 2018 If you don't already know the page and field name that $imageOK belongs to and have to work it out from the Pageimage then I suggest: $p = $imageOK->page; $field_name = $imageOK->field->name; $p->of(false); $p->$field_name->add('/full/disk/path/to/image_new.jpg'); $p->save($field_name); 3 Link to comment Share on other sites More sharing options...
felixthecat Posted December 10, 2018 Author Share Posted December 10, 2018 Thank you... that is working ? But what is the relation between pagimages and the field? Link to comment Share on other sites More sharing options...
Zeka Posted December 10, 2018 Share Posted December 10, 2018 42 minutes ago, felixthecat said: Thank you... that is working ? But what is the relation between pagimages and the field? Here is the description of Pageimages class ProcessWire Pageimages Pageimages are a collection of Pageimage objects. Typically a Pageimages object will be associated with a specific field attached to a Page. There may be multiple instances of Pageimages attached to a given Page (depending on what fields are in it's fieldgroup). https://processwire.com/apigen/class-Pageimages.html 2 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