예제 #1
0
파일: File.php 프로젝트: aoliverio/content
 /**
  * This function is used to uplodad file in /uploads/YEAR/MONTH directory 
  * and to create Content record contextually.
  * 
  * 
  * @param type $inputfile
  * @param string $destfile
  * @return boolean
  */
 public function upload($inputfile, $destfile = null)
 {
     if (strlen(trim($inputfile['name'])) === 0) {
         return FALSE;
     }
     $filename = strtolower($inputfile['name']);
     $sourcefile = $inputfile['tmp_name'];
     $file = new \Cake\Filesystem\File($sourcefile, true, 0775);
     $CONTENT_YEAR = date('Y');
     $CONTENT_MONTH = date('m');
     $UPLOAD_DIR = $this->path;
     $folder_dest = new Folder($UPLOAD_DIR);
     if (!$folder_dest->inCakePath($folder_dest->pwd() . DS . $CONTENT_YEAR)) {
         $folder_dest->create($folder_dest->pwd() . DS . $CONTENT_YEAR);
     }
     $folder_dest->cd($CONTENT_YEAR);
     if (!$folder_dest->inCakePath($folder_dest->pwd() . DS . $CONTENT_MONTH)) {
         $folder_dest->create($folder_dest->pwd() . DS . $CONTENT_MONTH);
     }
     $folder_dest->cd($CONTENT_MONTH);
     $path = DS . $CONTENT_YEAR . DS . $CONTENT_MONTH . DS;
     $permittedFilename = $this->getPermittedFilename($UPLOAD_DIR . $path, $filename);
     $destfile = $folder_dest->pwd() . DS . $permittedFilename;
     if ($file->copy($destfile, true)) {
         return $path . $permittedFilename;
     } else {
         return FALSE;
     }
 }
예제 #2
0
 /**
  * testInCakePath method
  *
  * @return void
  */
 public function testInCakePath()
 {
     $Folder = new Folder();
     $Folder->cd(ROOT);
     $path = 'C:\\path\\to\\file';
     $result = $Folder->inCakePath($path);
     $this->assertFalse($result);
     $path = ROOT;
     $Folder->cd(ROOT);
     $result = $Folder->inCakePath($path);
     $this->assertFalse($result);
     $path = DS . 'config';
     $Folder->cd(ROOT . DS . 'config');
     $result = $Folder->inCakePath($path);
     $this->assertTrue($result);
 }