Exemple #1
0
 /**
  * testIsSlashTerm method
  *
  * @return void
  */
 public function testIsSlashTerm()
 {
     $this->assertFalse(Folder::isSlashTerm('cake'));
     $this->assertTrue(Folder::isSlashTerm('C:\\cake\\'));
     $this->assertTrue(Folder::isSlashTerm('/usr/local/'));
 }
Exemple #2
0
 /**
  * Returns $path with added terminating slash (corrected for Windows or other OS).
  *
  * @param string $path Path to check
  * @return string Path with ending slash
  */
 public static function slashTerm($path)
 {
     if (Folder::isSlashTerm($path)) {
         return $path;
     }
     return $path . Folder::correctSlashFor($path);
 }
 /**
  * Saves the file.
  *
  * If you specify only a directory as target, it will keep the original
  *  filename of the file.
  * @param string $target Target
  * @return mixed Target path or `false` on failure
  * @uses _findTargetFilename()
  * @uses _setError()
  * @uses error()
  * @uses $file
  */
 public function save($target)
 {
     if (empty($this->file)) {
         throw new InternalErrorException(__d('me_tools', 'There are no uploaded file information'));
     }
     //Checks for previous errors
     if ($this->error()) {
         return false;
     }
     //If the target is a directory, then adds the filename
     if (is_dir($target)) {
         //Adds slash term
         if (!Folder::isSlashTerm($target)) {
             $target .= DS;
         }
         $target .= $this->file->name;
     }
     $target = $this->_findTargetFilename($target);
     if (!move_uploaded_file($this->file->tmp_name, $target)) {
         $this->_setError(__d('me_tools', 'The file was not successfully moved to the target directory'));
         return false;
     }
     return $target;
 }