本文整理汇总了PHP中OC\Files\Filesystem::fromTmpFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::fromTmpFile方法的具体用法?PHP Filesystem::fromTmpFile怎么用?PHP Filesystem::fromTmpFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::fromTmpFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
} else {
$target = \OC\Files\Filesystem::normalizePath(stripslashes($dir . $relativePath) . '/' . $files['name'][$i]);
}
// relative dir to return to the client
if (isset($publicDirectory)) {
// path relative to the public root
$returnedDir = $publicDirectory . $relativePath;
} else {
// full path
$returnedDir = $dir . $relativePath;
}
$returnedDir = \OC\Files\Filesystem::normalizePath($returnedDir);
if (!\OC\Files\Filesystem::file_exists($target) || isset($_POST['resolution']) && $_POST['resolution'] === 'replace') {
// upload and overwrite file
try {
if (is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
// updated max file size after upload
$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
$meta = \OC\Files\Filesystem::getFileInfo($target);
if ($meta === false) {
$error = $l->t('The target folder has been moved or deleted.');
$errorCode = 'targetnotfound';
} else {
$data = \OCA\Files\Helper::formatFileInfo($meta);
$data['status'] = 'success';
$data['originalname'] = $files['tmp_name'][$i];
$data['uploadMaxFilesize'] = $maxUploadFileSize;
$data['maxHumanFilesize'] = $maxHumanFileSize;
$data['permissions'] = $meta['permissions'] & $allowedPermissions;
$data['directory'] = $returnedDir;
$result[] = $data;
示例2: fromTmpFile
/**
* @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
*/
public static function fromTmpFile($tmpFile, $path)
{
return \OC\Files\Filesystem::fromTmpFile($tmpFile, $path);
}
示例3: UploadFiles
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function UploadFiles()
{
\OCP\JSON::setContentTypeHeader('text/plain');
if (!$this->AllowProtocolBT && !\OC_User::isAdminUser($this->CurrentUID)) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('You are not allowed to use the BitTorrent protocol')));
}
if (!isset($_FILES['files'])) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Error while uploading torrent file')));
} else {
if (!isset($_FILES['files']['name'][0])) {
throw new \Exception('Unable to find the uploaded file');
}
$Target = rtrim($this->TorrentsFolder, '/') . '/' . $_FILES['files']['name'][0];
try {
if (is_uploaded_file($_FILES['files']['tmp_name'][0]) && \OC\Files\Filesystem::fromTmpFile($_FILES['files']['tmp_name'][0], $Target)) {
$StorageStats = \OCA\Files\Helper::buildFileStorageStatistics($this->TorrentsFolder);
if (\OC\Files\Filesystem::getFileInfo($Target) !== false) {
return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Upload OK')));
}
} else {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Error while uploading torrent file')));
}
} catch (Exception $E) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
}
}
}
示例4: upload
/**
* @NoAdminRequired
* @NoCSRFRequired
* @SSOCORS
*/
public function upload($dir = '/')
{
\OC::$server->getSession()->close();
// Firefox and Konqueror tries to download application/json for me. --Arthur
\OCP\JSON::setContentTypeHeader('text/plain');
// If a directory token is sent along check if public upload is permitted.
// If not, check the login.
// If no token is sent along, rely on login only
$allowedPermissions = \OCP\Constants::PERMISSION_ALL;
$errorCode = null;
if (\OC\Files\Filesystem::file_exists($dir) === false) {
return new DataResponse(array('data' => array_merge(array('message' => 'Invalid directory.')), 'status' => 'error'));
}
// get array with current storage stats (e.g. max file size)
$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
$files = $this->request->getUploadedFile('files');
if (!isset($files)) {
return new DataResponse(array('data' => array_merge(array('message' => 'No file was uploaded. Unknown error'), $storageStats), 'status' => 'error'));
}
foreach ($files['error'] as $error) {
if ($error != 0) {
$errors = array(UPLOAD_ERR_OK => 'There is no error, the file uploaded with success', UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini: ' . ini_get('upload_max_filesize'), UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded', UPLOAD_ERR_NO_FILE => 'No file was uploaded', UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder', UPLOAD_ERR_CANT_WRITE => 'Failed to write to disk');
$errorMessage = $errors[$error];
\OC::$server->getLogger()->alert("Upload error: {$error} - {$errorMessage}", array('app' => 'files'));
return new DataResponse(array('data' => array_merge(array('message' => $errorMessage), $storageStats), 'status' => 'error'));
}
}
$error = false;
$maxUploadFileSize = $storageStats['uploadMaxFilesize'];
$maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize);
$totalSize = 0;
foreach ($files['size'] as $size) {
$totalSize += $size;
}
if ($maxUploadFileSize >= 0 and $totalSize > $maxUploadFileSize) {
return new DataResponse(array('data' => array('message' => 'Not enough storage available', 'uploadMaxFilesize' => $maxUploadFileSize, ' maxHumanFilesize' => $maxHumanFileSize), 'status' => 'error'));
}
$result = array();
$fileCount = count($files['name']);
for ($i = 0; $i < $fileCount; $i++) {
// target directory for when uploading folders
$relativePath = '';
$target = \OC\Files\Filesystem::normalizePath($dir . $relativePath . '/' . $files['name'][$i]);
// relative dir to return to the client
if (isset($publicDirectory)) {
// path relative to the public root
$returnedDir = $publicDirectory . $relativePath;
} else {
// full path
$returnedDir = $dir . $relativePath;
}
$returnedDir = \OC\Files\Filesystem::normalizePath($returnedDir);
$exists = \OC\Files\Filesystem::file_exists($target);
if ($exists) {
$target = \OCP\Files::buildNotExistingFileName($dir . $relativePath, $files['name'][$i]);
}
try {
if (is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
// updated max file size after upload
$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
$meta = \OC\Files\Filesystem::getFileInfo($target);
if ($meta === false) {
$error = 'The target folder has been moved or deleted.';
$errorCode = 'targetnotfound';
} else {
$data = \OCA\Files\Helper::formatFileInfo($meta);
$data['originalname'] = $files['name'][$i];
$data['uploadMaxFilesize'] = $maxUploadFileSize;
$data['maxHumanFilesize'] = $maxHumanFileSize;
$data['permissions'] = $meta['permissions'] & $allowedPermissions;
$data['directory'] = $returnedDir;
$result[] = $data;
}
} else {
$error = 'Upload failed. Could not find uploaded file';
}
} catch (Exception $ex) {
$error = $ex->getMessage();
}
}
if ($error === false) {
$result = \OCP\JSON::encode($result);
return new DataResponse(array('data' => $result, 'status' => 'success'));
} else {
return new DataResponse(array('data' => array_merge(array('message' => $error, 'code' => $errorCode), $storageStats), 'status' => 'error'));
}
}