コード例 #1
0
 public function testMoveTo()
 {
     //existing file
     $this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext'));
     $this->assertFalse(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/myFile.ext'));
     $originalContent = file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext');
     $this->assertTrue($this->fixture_file->moveTo($this->fixture_dir));
     $this->assertFalse(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext'));
     $this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/myFile.ext'));
     $this->assertEquals($originalContent, file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/myFile.ext'));
     unlink(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/myFile.ext');
     //non-existing file
     $this->assertFalse(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext'));
     try {
         $this->fixture_file->moveTo($this->fixture_dir);
         $fail->fail();
     } catch (EyeFileNotFoundException $e) {
         // normal situation
     }
     //existing directory containing files
     mkdir(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1');
     $dir = new LocalFile(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1');
     $originalContent = '## test - content ##';
     file_put_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1/mySubFile.ext', $originalContent);
     $this->assertTrue(is_dir(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1'));
     $this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1/mySubFile.ext'));
     $this->assertTrue($dir->moveTo($this->fixture_dir));
     $this->assertFalse(is_dir(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1'));
     $this->assertTrue(is_dir(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1'));
     $this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1/mySubFile.ext'));
     $this->assertEquals($originalContent, file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1/mySubFile.ext'));
     unlink(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1/mySubFile.ext');
     rmdir(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1');
 }
コード例 #2
0
ファイル: upload.php プロジェクト: sebasalons/eyeos-u1db
 public static function submitFile($path)
 {
     try {
         if (!isset($_FILES['Filedata'])) {
             echo '<div style="font-size:20px;font-family:Helvetica, Arial, Verdana, Sans, FreeSans;margin-top:80px;margin-right:15px;"><center>&nbsp;&nbsp;<img style="position:relative;top:15px"src="index.php?extern=/images/48x48/actions/dialog-close.png" />Error uploading files</center>';
             exit;
         }
         $Logger = Logger::getLogger('application.upload');
         foreach ($_FILES['Filedata']['name'] as $k => $v) {
             if (!empty($v)) {
                 $filename = $_FILES['Filedata']['name'][$k];
                 if (!isset($_POST['UPLOAD_IDENTIFIER'])) {
                     $filename = utf8_encode($filename);
                 }
                 $tmpPath = $_FILES['Filedata']['tmp_name'][$k];
                 $Logger->debug("Filename: " . $filename);
                 if (!is_uploaded_file($tmpPath)) {
                     throw new EyeFileNotFoundException('Uploaded file not found at "' . $tmpPath . '".');
                 }
                 $request = MMapManager::getCurrentRequest();
                 $destPath = $path;
                 $filename = str_replace('?', '_', $filename);
                 $filename = str_replace('#', '_', $filename);
                 $tmp = pathinfo($filename);
                 if (isset($tmp['extension']) && "lnk" == $tmp['extension']) {
                     throw new EyeFileNotFoundException('This file cannot be uploaded (file type banned)');
                 }
                 /*
                 if ( '?' == $filename{0} ) {
                 	$filename{0} = "_";
                 }
                 */
                 $destFile = FSI::getFile($destPath . '/' . $filename);
                 //The uploaded file is necessarily on the local filesystem and we want to avoid any
                 //permission check through EyeLocalFile, so we use LocalFile directly
                 $tmpFile = new LocalFile($tmpPath);
                 $num = 1;
                 $extension = AdvancedPathLib::pathinfo($filename, PATHINFO_EXTENSION);
                 $filename = AdvancedPathLib::pathinfo($filename, PATHINFO_FILENAME);
                 $Logger->debug("CLASS: " . get_class($destFile));
                 $Logger->debug("Exists: " . $destFile->exists());
                 //exit();
                 while ($destFile->exists()) {
                     $newBasename = $filename . ' (' . $num++ . ')' . ($extension ? '.' . $extension : '');
                     $destFile = FSI::getFile($destPath . '/' . $newBasename);
                 }
                 $destFile->checkWritePermission();
                 $tmpFile->moveTo($destFile);
                 $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
                 $settings = MetaManager::getInstance()->retrieveMeta($currentUser);
                 $message = new ClientBusMessage('file', 'uploadComplete', self::getFileInfo($destFile, $settings));
                 ClientMessageBusController::getInstance()->queueMessage($message);
                 $event = new FileEvent($destFile);
                 $destFile->fireEvent('fileWritten', $event);
             }
         }
         register_shutdown_function('endRequestUpload');
     } catch (EyeException $e) {
         echo '<div style="font-size:20px;font-family:Helvetica, Arial, Verdana, Sans, FreeSans;margin-top:80px;margin-right:15px;"><center>&nbsp;&nbsp;<img style="position:relative;top:15px"src="index.php?extern=/images/48x48/actions/dialog-close.png" />Error uploading files: ' . $e->getMessage() . '</center>';
         exit;
     }
 }
コード例 #3
0
ファイル: LocalFile.php プロジェクト: DavidGarciaCat/eyeos
 /**
  * @return bool TRUE if the file has been successfully moved, FALSE otherwise
  */
 public function moveTo(IFile $file)
 {
     $this->getParentFile()->checkWritePermission();
     $this->checkReadPermission();
     return parent::moveTo($file);
 }