Run thumbnail resizing Script using Trigger aftersave?

A place for users and developers of the Xataface to discuss and receive support.

Run thumbnail resizing Script using Trigger aftersave?

Postby ge11er » Fri Oct 09, 2009 12:47 pm

I need to create thumbnail images from images that are uploaded to the file system. I have script that will do the resizing and saving to the file system.

If I manually supply the script with the uploaded 'image name' and import the script into the tables delegate class it will run.

Ideally the script would run only after inserting/uploading an image.

upload image > afterSave trigger > pass 'image file name' to script > run script(resize.inc)

Any help/guidance would be appreciated.
ge11er
 
Posts: 18
Joined: Wed Feb 11, 2009 4:52 pm

Postby ge11er » Sat Oct 17, 2009 12:39 pm

Got this working using trigger 'aftersave' but a minor issue now when I delete the image from the file system I get a dialog box saying 'Failed to delete file'.

When I refresh the page the file has been delete. I am not sure how this is related to my trigger as It should only run after 'saving' an image only i think?

Code: Select all
function afterSave(&$record){
$imageField =& $record->_table->getField('image');
require ('resizescript.php');
}


Again any help appreciated.
ge11er
 
Posts: 18
Joined: Wed Feb 11, 2009 4:52 pm

Postby shannah » Mon Oct 19, 2009 4:09 pm

When you resize the file are you renaming it? Xataface checks for the existing file when deleting it based on the file name stored in the db. If you are renaming the file, it won't be able to find the one to delete. That is one guess at what could be happening.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby ge11er » Mon Nov 02, 2009 6:53 am

Had another look at this one and it appears that the resize script is running even if no image has been added or updated.

My php is terrible have I written the trigger correctly?

Cheers
Graham
ge11er
 
Posts: 18
Joined: Wed Feb 11, 2009 4:52 pm

Postby Jean » Mon Nov 02, 2009 8:34 am

Hi Graham,

Try this :

Code: Select all
function afterSave(&$record){
if ($record->strval('image')){
$imageField =& $record->_table->getField('image');
require ('resizescript.php');
}
}


Jean :)
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby shannah » Mon Nov 02, 2009 8:49 am

Further improvement:
Code: Select all
function beforeSave(&$record){
    if ( $record->valueChanged('image') and $record->val('image')){
        $record->pouch['image_changed'] = true;
    }
}
function afterSave(&$record){
  if ($record->pouch['image_changed']){
    $record->pouch['image_changed'] = null;
    $imageField =& $record->_table->getField('image');
    require ('resizescript.php');
  }
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Jean » Mon Nov 02, 2009 9:15 am

Hi Graham,

Try this :

Code: Select all
function afterSave(&$record){
if ($record->strval('image')){
$imageField =& $record->_table->getField('image');
require ('resizescript.php');
}
}


Jean :)
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Postby ge11er » Mon Nov 02, 2009 12:47 pm

Thanks guys thats sorted it.

Cheers
Graham
ge11er
 
Posts: 18
Joined: Wed Feb 11, 2009 4:52 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 22 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved