本文整理汇总了PHP中Bitrix\Main\IO\File::getSize方法的典型用法代码示例。如果您正苦于以下问题:PHP File::getSize方法的具体用法?PHP File::getSize怎么用?PHP File::getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitrix\Main\IO\File
的用法示例。
在下文中一共展示了File::getSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: repackDocument
/**
* Repacks exported document from Google.Drive, which has wrong order files in archive to show preview
* in Google.Viewer. In Google.Viewer document should have file '[Content_Types].xml' on first position in archive.
* @param FileData $fileData
* @return FileData
* @throws IO\FileNotFoundException
* @throws IO\InvalidPathException
* @internal
*/
public function repackDocument(FileData $fileData)
{
if (!extension_loaded('zip')) {
return null;
}
if (!TypeFile::isDocument($fileData->getName())) {
return null;
}
$file = new IO\File($fileData->getSrc());
if (!$file->isExists() || $file->getSize() > 15 * 1024 * 1024) {
return null;
}
unset($file);
$ds = DIRECTORY_SEPARATOR;
$targetDir = \CTempFile::getDirectoryName(2, 'disk_repack' . $ds . md5(uniqid('di', true)));
checkDirPath($targetDir);
$targetDir = IO\Path::normalize($targetDir) . $ds;
$zipOrigin = new \ZipArchive();
if (!$zipOrigin->open($fileData->getSrc())) {
return null;
}
if ($zipOrigin->getNameIndex(0) === '[Content_Types].xml') {
$zipOrigin->close();
return null;
}
if (!$zipOrigin->extractTo($targetDir)) {
$zipOrigin->close();
return null;
}
$zipOrigin->close();
unset($zipOrigin);
if (is_dir($targetDir) !== true) {
return null;
}
$newName = md5(uniqid('di', true));
$newFilepath = $targetDir . '..' . $ds . $newName;
$repackedZip = new \ZipArchive();
if (!$repackedZip->open($newFilepath, \ZipArchive::CREATE)) {
return null;
}
$source = realpath($targetDir);
$repackedZip->addFile($source . $ds . '[Content_Types].xml', '[Content_Types].xml');
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
if ($file->getBasename() === '[Content_Types].xml') {
continue;
}
$file = str_replace('\\', '/', $file);
$file = realpath($file);
if (is_dir($file) === true) {
$repackedZip->addEmptyDir(str_replace('\\', '/', str_replace($source . $ds, '', $file . $ds)));
} elseif (is_file($file) === true) {
$repackedZip->addFile($file, str_replace('\\', '/', str_replace($source . $ds, '', $file)));
}
}
$repackedZip->close();
$newFileData = new FileData();
$newFileData->setSrc($newFilepath);
return $newFileData;
}
示例2: getReplacedImageCid
/**
* @param $matches
* @return string
* @throws \Bitrix\Main\IO\FileNotFoundException
*/
protected function getReplacedImageCid($matches)
{
$src = $matches[3];
if ($src == "") {
return $matches[0];
}
if (array_key_exists($src, $this->filesReplacedFromBody)) {
$uid = $this->filesReplacedFromBody[$src]["ID"];
return $matches[1] . $matches[2] . "cid:" . $uid . $matches[4] . $matches[5];
}
$io = \CBXVirtualIo::GetInstance();
$filePath = $io->GetPhysicalName(\Bitrix\Main\Application::getDocumentRoot() . $src);
if (!File::isFileExists($filePath)) {
return $matches[0];
}
foreach ($this->attachment as $attach) {
if ($filePath == $attach['PATH']) {
return $matches[1] . $matches[2] . "cid:" . $attach['ID'] . $matches[4] . $matches[5];
}
}
if ($this->settingMaxFileSize > 0) {
$fileIoObject = new File($filePath);
if ($fileIoObject->getSize() > $this->settingMaxFileSize) {
return $matches[0];
}
}
$aImage = \CFile::GetImageSize($filePath, true);
if (!is_array($aImage)) {
return $matches[0];
}
if (function_exists("image_type_to_mime_type")) {
$contentType = image_type_to_mime_type($aImage[2]);
} else {
$contentType = $this->imageTypeToMimeType($aImage[2]);
}
$uid = uniqid(md5($src));
$this->filesReplacedFromBody[$src] = array("SRC" => $src, "PATH" => $filePath, "CONTENT_TYPE" => $contentType, "NAME" => bx_basename($src), "ID" => $uid);
return $matches[1] . $matches[2] . "cid:" . $uid . $matches[4] . $matches[5];
}
示例3: SaveFile
function SaveFile($arFile, $strSavePath, $bForceMD5 = false, $bSkipExt = false)
{
$strFileName = GetFileName($arFile["name"]);
/* filename.gif */
if (isset($arFile["del"]) && $arFile["del"] != '') {
CFile::DoDelete($arFile["old_file"]);
if ($strFileName == '') {
return "NULL";
}
}
if ($arFile["name"] == '') {
if (isset($arFile["description"]) && intval($arFile["old_file"]) > 0) {
CFile::UpdateDesc($arFile["old_file"], $arFile["description"]);
}
return false;
}
if (isset($arFile["content"])) {
if (!isset($arFile["size"])) {
$arFile["size"] = CUtil::BinStrlen($arFile["content"]);
}
} else {
try {
$file = new IO\File($arFile["tmp_name"]);
$arFile["size"] = $file->getSize();
} catch (IO\IoException $e) {
$arFile["size"] = 0;
}
}
$arFile["ORIGINAL_NAME"] = $strFileName;
//translit, replace unsafe chars, etc.
$strFileName = self::transformName($strFileName, $bForceMD5, $bSkipExt);
//transformed name must be valid, check disk quota, etc.
if (self::validateFile($strFileName, $arFile) !== "") {
return false;
}
if ($arFile["type"] == "image/pjpeg" || $arFile["type"] == "image/jpg") {
$arFile["type"] = "image/jpeg";
}
$bExternalStorage = false;
foreach (GetModuleEvents("main", "OnFileSave", true) as $arEvent) {
if (ExecuteModuleEventEx($arEvent, array(&$arFile, $strFileName, $strSavePath, $bForceMD5, $bSkipExt))) {
$bExternalStorage = true;
break;
}
}
if (!$bExternalStorage) {
$upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
$io = CBXVirtualIo::GetInstance();
if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") {
$dir_add = '';
$i = 0;
while (true) {
$dir_add = substr(md5(uniqid("", true)), 0, 3);
if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $dir_add . "/" . $strFileName)) {
break;
}
if ($i >= 25) {
$j = 0;
while (true) {
$dir_add = substr(md5(mt_rand()), 0, 3) . "/" . substr(md5(mt_rand()), 0, 3);
if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $dir_add . "/" . $strFileName)) {
break;
}
if ($j >= 25) {
$dir_add = substr(md5(mt_rand()), 0, 3) . "/" . md5(mt_rand());
break;
}
$j++;
}
break;
}
$i++;
}
if (substr($strSavePath, -1, 1) != "/") {
$strSavePath .= "/" . $dir_add;
} else {
$strSavePath .= $dir_add . "/";
}
} else {
$strFileExt = $bSkipExt == true || ($ext = GetFileExtension($strFileName)) == '' ? '' : "." . $ext;
while (true) {
if (substr($strSavePath, -1, 1) != "/") {
$strSavePath .= "/" . substr($strFileName, 0, 3);
} else {
$strSavePath .= substr($strFileName, 0, 3) . "/";
}
if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $strFileName)) {
break;
}
//try the new name
$strFileName = md5(uniqid("", true)) . $strFileExt;
}
}
$arFile["SUBDIR"] = $strSavePath;
$arFile["FILE_NAME"] = $strFileName;
$strDirName = $_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/";
$strDbFileNameX = $strDirName . $strFileName;
$strPhysicalFileNameX = $io->GetPhysicalName($strDbFileNameX);
CheckDirPath($strDirName);
if (is_set($arFile, "content")) {
//.........这里部分代码省略.........
示例4: uploadEmptyFileFromGoogle
/**
* Fix for Google. It does not get in metadata real size of empty file.
* @param Entry $entry
* @param Document\FileData $fileData
* @return bool
* @throws IO\FileNotFoundException
* @throws \Bitrix\Main\SystemException
*/
protected function uploadEmptyFileFromGoogle(Entry $entry, Document\FileData $fileData)
{
$tmpFile = $fileData->getSrc();
$downloadedContentSize = $entry->getDownloadedContentSize();
$startRange = $downloadedContentSize;
//fix for Google. It doesn't get in metadata real size of empty file.
if (!$this->documentHandler->downloadFile($fileData)) {
$this->errorCollection->add($this->documentHandler->getErrors());
return false;
}
$realFile = new IO\File($tmpFile);
$contentSize = $realFile->getSize();
$entry->setContentSize($contentSize);
$chunkSize = $contentSize - $downloadedContentSize;
$uploadFileManager = new Bitrix24Disk\UploadFileManager();
$uploadFileManager->setTmpFileClass(TmpFile::className())->setUser($this->documentHandler->getUserId())->setFileSize($contentSize)->setContentRange(array($startRange, $startRange + $chunkSize - 1));
$tmpFileArray = \CFile::makeFileArray($tmpFile);
if (!$uploadFileManager->upload($fileData->getId(), $tmpFileArray)) {
$this->errorCollection->add($uploadFileManager->getErrors());
return false;
}
$entry->linkTmpFile(TmpFile::load(array('=TOKEN' => $uploadFileManager->getToken())));
return $entry->increaseDownloadedContentSize($chunkSize);
}