Jump to content

Hook, get .png file from file field and upload it to image field


picarica
 Share

Recommended Posts

So hello i am trying to get a .png file from file field and put it automatically to image field, why png image is in the file field is because i already have a hook that extracts .zip and uploads all content into file field, but i just realizes i cant use size() function on image in file field so i am tryin got reupload it to images field

i already have something like  this in ready.php

  $word = ".png";
    foreach($page->subor_hry as $file) {
        if(strpos($file, $word) !== false){
      		$page->images_thumb = $file->url;
        }
    }    

by my logic it should work but it dosnt i get error ProcessPageEdit: Unable to read: /site-hry/assets/files/1027/flash_fishy_screenshot.png

when i remove url from $file->url i just get ProcessPageEdit: Item added to ProcessWire\Pageimages is not an allowed type

so what am i doing wrong? is there some other way to do this ?
also can i have all this in

$this->addHookAfter('Pages::saveReady', function(HookEvent $event) {

whats the correct function to have it apply on all pages ?

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

×
×
  • Create New...