Created
March 6, 2015 14:26
-
-
Save damianoporta/6616428a82e4a47ab4a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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