/**
  * Returns an scaled version of the given file image.
  *
  * The following GET variables must be set on request:
  *
  * - file: The image's file name to scale.
  * - size: A preview size name, sett `ImageToolbox::getPreviews()`
  *
  * If any of these variables is not present an exception will be throw.
  *
  * @param string $name EAV attribute name
  * @return \Cake\Network\Response
  * @throws \Cake\Network\Exception\NotFoundException When field instance
  *  is not found.
  */
 public function thumbnail($name)
 {
     $this->loadModel('Field.FieldInstances');
     $instance = $this->_getInstance($name);
     if (!$instance) {
         throw new NotFoundException(__d('field', 'Invalid field instance.'), 400);
     }
     if (empty($this->request->query['file'])) {
         throw new NotFoundException(__d('field', 'Invalid file name.'), 400);
     }
     if (empty($this->request->query['size'])) {
         throw new NotFoundException(__d('field', 'Invalid image size.'), 400);
     }
     $imagePath = normalizePath(WWW_ROOT . "/files/{$instance->settings['upload_folder']}/{$this->request->query['file']}");
     $tmb = ImageToolbox::thumbnail($imagePath, $this->request->query['size']);
     if ($tmb !== false) {
         $this->response->file($tmb);
         return $this->response;
     }
     throw new NotFoundException(__d('field', 'Thumbnail could not be found, check write permissions?'), 500);
 }
Ejemplo n.º 2
0
 /**
  * test delete() method.
  *
  * @return void
  */
 public function testDelete()
 {
     copy($this->img2, WWW_ROOT . 'files/dummy-test.png');
     ImageToolbox::delete(WWW_ROOT . 'files/dummy-test.png');
     $this->assertFalse(file_exists(WWW_ROOT . 'files/dummy-test.png'));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function beforeDelete(Field $field)
 {
     foreach ((array) $field->extra as $image) {
         if (!empty($image['file_name'])) {
             ImageToolbox::delete(WWW_ROOT . "/files/{$field->settings['upload_folder']}/{$image['file_name']}");
         }
     }
 }