本文整理汇总了PHP中LocalFile::moveTo方法的典型用法代码示例。如果您正苦于以下问题:PHP LocalFile::moveTo方法的具体用法?PHP LocalFile::moveTo怎么用?PHP LocalFile::moveTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocalFile
的用法示例。
在下文中一共展示了LocalFile::moveTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMoveTo
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: submitFile
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> <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> <img style="position:relative;top:15px"src="index.php?extern=/images/48x48/actions/dialog-close.png" />Error uploading files: ' . $e->getMessage() . '</center>';
exit;
}
}
示例3: moveTo
/**
* @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);
}