Beispiel #1
0
 /**
  * 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;
 }