/**
  * Saves the uploaded file.
  *
  * This method can throw exceptions if there is a problem when saving the file.
  *
  * If you don't pass a file name, it will be generated by the generateFilename method.
  * This will only work if you have passed a path when initializing this instance.
  *
  * @param  string $file      The file path to save the file
  * @param  int    $fileMode  The octal mode to use for the new file
  * @param  bool   $create    Indicates that we should make the directory before moving the file
  * @param  int    $dirMode   The octal mode to use when creating the directory
  *
  * @return string The filename without the $this->path prefix
  *
  * @throws Exception
  */
 public function save($file = null, $fileMode = null, $create = true, $dirMode = 0777)
 {
     if ($file === null) {
         if ($this->originalName === null) {
             $file = $this->generateFilename();
         } else {
             $file = $this->originalName;
         }
     }
     $filebase = $this->manager->getFilebase();
     // copy the temp file to the destination file
     $file = $filebase->getFilebaseFile($this->getTempName())->copy($file, true);
     // chmod our file
     if ($fileMode !== null) {
         $file->chmod($fileMode);
     }
     $this->savedName = $file->getPathname();
     return $file;
 }
 /**
  * Moves an uploaded File to specified Destination.
  * Inclusion and exclusion rules consist of regex-strings,
  * they are used to check the target filenames against them.
  * Exclusion:   Matched filenames throw exceptions.
  * Incluseion:  Matched filenames will be passed as valid filenames.
  *
  * $destination can be a string (absolute or relative pathname) or an
  * instance of sfFilebasePluginFile, it is the directory, not the full pathName of
  * the new file. The file can be renamed by setting $file_name, otherwise
  * the original name will be taken as filename.
  *
  * @param mixed $tmp_file
  * @param mixed $destination_directory: The directory the file will be moved in.
  * @param string $file_name: If given, file will be renamed when moving.
  * @param boolean $override True if existing files should be overwritten
  * @param array $inclusion_rules
  * @param array $exclusion_rules
  * @throws sfFilebasePluginException
  * @return sfFilebasePluginFile $moved_file
  */
 public function moveUploadedFile(sfFilebasePluginUploadedFile $tmp_file, $destination_directory, $file_name = null, $override = true, $chmod = null, array $inclusion_rules = array(), $exclusion_rules = array())
 {
     return $this->uploadedFilesManager->moveUploadedFile($tmp_file, $destination_directory, $file_name, $override, $chmod, $inclusion_rules, $exclusion_rules);
 }
 /**
  * Returns the data describing
  * uploaded files to handle by
  * move uploaded files.
  *
  * @param  mixed $index: The array index. If none given, the whole
  *                       transformed file will be returned.
  * @return array sfFilebasePluginUploadedFile $files
  */
 public function getUploadedFiles($index = null)
 {
     // Look for cached upload-info
     if (is_array(self::$UPLOADED_FILES)) {
         return $index === null ? self::$UPLOADED_FILES : self::$UPLOADED_FILES[$index];
     }
     $files = array();
     foreach ($_FILES as $i => $entry) {
         if (self::isUploadedFile($entry)) {
             $names = array();
             $types = array();
             $tmp_names = array();
             $errors = array();
             $sizes = array();
             // field, can be multi dimensional.
             if (is_array($entry['tmp_name'])) {
                 $names = $entry['name'];
                 $types = $entry['type'];
                 $tmp_names = $entry['tmp_name'];
                 $errors = $entry['error'];
                 $sizes = $entry['size'];
             } else {
                 $names = array($entry['name']);
                 $types = array($entry['type']);
                 $tmp_names = array($entry['tmp_name']);
                 $errors = array($entry['error']);
                 $sizes = array($entry['size']);
             }
             $files[$i] = $this->recurseFilesArray($names, $tmp_names, $types, $errors, $sizes);
         }
     }
     self::$UPLOADED_FILES = $files;
     return $this->getUploadedFiles($index);
 }
 /**
  * @see sfValidatorBase
  */
 protected function isEmpty($value)
 {
     // empty if the value is not an array
     // or if the value comes from PHP with an error of UPLOAD_ERR_NO_FILE
     if ($value instanceof sfFilebasePluginUploadedFile) {
         return $value->isError(sfFilebasePluginUploadedFile::UPLOAD_ERR_NO_FILE);
     } else {
         return sfFilebasePluginUploadedFilesManager::isUploadedFile($value);
     }
 }