public function test_save_and_delete() { $image = Jam::build('test_image'); $image->file = Upload_Util::combine($this->test_local, 'source', 'logo.gif'); $image->save(); $file = $image->file->file(); $this->assertFileExists($file); $image->delete(); $this->assertFileNotExists($file); }
/** * Copy the source data to a directory * * @param string $directory * @return Upload_Source $this */ public function copy_to($directory) { switch ($this->type()) { case Upload_Source::TYPE_URL: $filename = Upload_Util::download($this->data(), $directory, $this->filename()); $this->filename($filename); break; case Upload_Source::TYPE_UPLOAD: try { $filename = Upload_Source::process_type_upload($this->data(), $directory); $this->filename($filename); } catch (Jam_Exception_Upload $e) { $this->error($e->getMessage()); } break; case Upload_Source::TYPE_STREAM: if (!$this->filename()) { $this->filename(uniqid()); } Upload_Util::stream_copy_to_file($this->data(), Upload_Util::combine($directory, $this->filename())); break; case Upload_Source::TYPE_FILE: if (!Upload_Source::valid_file($this->data())) { throw new Kohana_Exception("File must be in the document root, or must be testing environment"); } if (!$this->filename()) { $this->filename(basename($this->data())); } copy($this->data(), Upload_Util::combine($directory, $this->filename())); break; case Upload_Source::TYPE_TEMP: if (!Upload_Temp::valid($this->data())) { throw new Kohana_Exception("This file does not exist"); } $this->filename(basename($this->data())); break; } $this->_copied = TRUE; return $this; }
protected function location($method, $thumbnail = NULL) { if (!$this->filename()) { return NULL; } try { if ($this->_source) { return $this->temp()->{$method}(Upload_Util::combine($this->temp()->directory(), $thumbnail, $this->filename())); } else { return $this->server()->{$method}($this->full_path($thumbnail)); } } catch (Flex\Storage\Exception_Notsupported $exception) { return NULL; } }
public function url($path, $thumbnail = NULL) { return Upload_Util::combine(Upload_Temp::config('web'), $path, $thumbnail); }
/** * @dataProvider data_is_filename */ public function test_is_filename($filename, $is_filename) { $this->assertEquals($is_filename, Upload_Util::is_filename($filename)); }
/** * Detirmine the filename from the url * @param string $url * @param string $mime_type * @return string */ public static function filename_from_url($url, $mime_type = NULL) { $filename_candidates = Upload_Util::filenames_candidates_from_url($url); $filename_candidates = array_filter($filename_candidates, 'Upload_Util::is_filename'); $file = count($filename_candidates) ? reset($filename_candidates) : uniqid(); $extensions = File::exts_by_mime($mime_type); $extension_candiates = array(is_array($extensions) ? end($extensions) : $extensions, pathinfo($file, PATHINFO_EXTENSION), 'jpg'); $extension_candiates = array_filter($extension_candiates); $extension = reset($extension_candiates); return Upload_Util::sanitize(pathinfo($file, PATHINFO_FILENAME)) . '.' . $extension; }
public function test_multiple_rules() { // Logo is 127 x 34 $this->value->source(Upload_Util::combine($this->test_local, 'source', 'logo.gif'))->save_to_temp(); Jam::validator_rule('uploaded', array('only' => array('png'), 'maximum_size' => '1B', 'exact_height' => 20))->validate($this->model, 'file', $this->value); $this->assertHasError($this->model, 'file', 'uploaded_extension'); $this->assertHasError($this->model, 'file', 'uploaded_maximum_size'); $this->assertHasError($this->model, 'file', 'uploaded_exact_height'); }