Skip to content

Instantly share code, notes, and snippets.

@damianoporta
Created March 6, 2015 14:26
Show Gist options
  • Save damianoporta/6616428a82e4a47ab4a7 to your computer and use it in GitHub Desktop.
Save damianoporta/6616428a82e4a47ab4a7 to your computer and use it in GitHub Desktop.
<?php
public function beforeSave(Event $event, Entity $entity, ArrayObject $options, ProfferPath $path = null)
{
foreach ($this->config() as $field => $settings) {
if ($entity->has($field) && is_array($entity->get($field)) &&
$entity->get($field)['error'] === UPLOAD_ERR_OK) {
if (!$path) {
$path = new ProfferPath($this->_table, $entity, $field, $settings);
}
$path->createPathFolder();
if ($this->moveUploadedFile($entity->get($field)['tmp_name'], $path->fullPath())) {
$entity->set($field, $entity->get($field)['name']);
$entity->set($settings['dir'], $path->getSeed());
// Don't generate thumbnails for non-images
if (getimagesize($path->fullPath()) !== false) {
$this->makeThumbs($field, $path);
}
} else {
throw new Exception('Cannot move file');
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment