本文整理汇总了PHP中CFile::GetByID方法的典型用法代码示例。如果您正苦于以下问题:PHP CFile::GetByID方法的具体用法?PHP CFile::GetByID怎么用?PHP CFile::GetByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFile
的用法示例。
在下文中一共展示了CFile::GetByID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Delete
/**
* <p>Метод удаляет файл из таблицы зарегистрированных файлов (b_file) и с диска. Статичный метод.</p>
*
*
* @param int $id Цифровой идентификатор файла.
*
* @return mixed
*
* <h4>Example</h4>
* <pre>
* <?
* // удаляем изображение формы
* $arFilter = array("ID" => 1, "ID_EXACT_MATCH" => "Y");
* $rsForm = CForm::GetList($by, $order, $arFilter, $is_filtered);
* if ($arForm = $rsForm->Fetch())
* {
* if (intval($arForm["IMAGE_ID"])>0) <b>CFile::Delete</b>($arForm["IMAGE_ID"]);
* }
* ?>
* </pre>
*
*
* <h4>See Also</h4>
* <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/main/functions/file/deletedirfiles.php">DeleteDirFiles</a> </li>
* <li> <a href="http://dev.1c-bitrix.ru/api_help/main/functions/file/deletedirfilesex.php">DeleteDirFilesEx</a> </li>
* </ul><a name="examples"></a>
*
*
* @static
* @link http://dev.1c-bitrix.ru/api_help/main/reference/cfile/delete.php
* @author Bitrix
*/
public static function Delete($ID)
{
global $DB;
$io = CBXVirtualIo::GetInstance();
$ID = intval($ID);
if ($ID <= 0) {
return;
}
$res = CFile::GetByID($ID);
if ($res = $res->Fetch()) {
$delete_size = 0;
$upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
$dname = $_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $res["SUBDIR"];
$fname = $dname . "/" . $res["FILE_NAME"];
$file = $io->GetFile($fname);
if ($file->isExists() && $file->unlink()) {
$delete_size += $res["FILE_SIZE"];
}
$delete_size += CFile::ResizeImageDelete($res);
$DB->Query("DELETE FROM b_file WHERE ID = " . $ID);
$directory = $io->GetDirectory($dname);
if ($directory->isExists() && $directory->isEmpty()) {
$directory->rmdir();
}
CFile::CleanCache($ID);
foreach (GetModuleEvents("main", "OnFileDelete", true) as $arEvent) {
ExecuteModuleEventEx($arEvent, array($res));
}
/****************************** QUOTA ******************************/
if ($delete_size > 0 && COption::GetOptionInt("main", "disk_space") > 0) {
CDiskQuota::updateDiskQuota("file", $delete_size, "delete");
}
/****************************** QUOTA ******************************/
}
}
示例2: __main_post_form_image_resize
function __main_post_form_image_resize(&$arCustomFile, $arParams = null)
{
static $arResizeParams = array();
if ($arParams !== null) {
if (is_array($arParams) && array_key_exists("width", $arParams) && array_key_exists("height", $arParams)) {
$arResizeParams = $arParams;
} elseif (intVal($arParams) > 0) {
$arResizeParams = array("width" => intVal($arParams), "height" => intVal($arParams));
}
}
if (!is_array($arCustomFile) || !isset($arCustomFile['fileID'])) {
return false;
}
if (array_key_exists("ID", $arCustomFile)) {
$arFile = $arCustomFile;
$fileID = $arCustomFile['ID'];
} else {
$fileID = $arCustomFile['fileID'];
$arFile = CFile::MakeFileArray($fileID);
$arFile1 = CFile::GetByID($fileID)->fetch();
if (is_array($arFile) && is_array($arFile1)) {
$arCustomFile = array_merge($arFile, $arFile1, $arCustomFile);
}
}
if (CFile::CheckImageFile($arFile) === null) {
$aImgThumb = CFile::ResizeImageGet($fileID, array("width" => 90, "height" => 90), BX_RESIZE_IMAGE_EXACT, true);
$arCustomFile['img_thumb_src'] = $aImgThumb['src'];
if (!empty($arResizeParams)) {
$aImgSource = CFile::ResizeImageGet($fileID, array("width" => $arResizeParams["width"], "height" => $arResizeParams["height"]), BX_RESIZE_IMAGE_PROPORTIONAL, true);
$arCustomFile['img_source_src'] = $aImgSource['src'];
$arCustomFile['img_source_width'] = $aImgSource['width'];
$arCustomFile['img_source_height'] = $aImgSource['height'];
}
}
}
示例3: fromId
/**
* @static
* @param $id
* @return \BitrixHelperLib\Classes\Block\File
* @throws \Exception
*/
static function fromId($id)
{
if (!($file = \CFile::GetByID($id)->GetNext())) {
throw new \Exception('File with id ' . $id . ' does not exist');
}
$className = get_called_class();
return new $className($file);
}
示例4: getImageUrl
public function getImageUrl($key)
{
if (!$this->hasImage($key)) {
throw new \Exception(__CLASS__ . ' with ID ' . $this->id . ' does not have image ' . $key);
}
if (empty($this->imagesSrc[$key])) {
if ($file = \CFile::GetByID($this->getImageId($key))->GetNext()) {
$this->imagesSrc[$key] = \CFile::GetFileSRC($file);
}
}
return $this->imagesSrc[$key];
}
示例5: generateRow
/**
* {@inheritdoc}
*/
public function generateRow(&$row, $data)
{
$html = '';
if ($this->getSettings('MULTIPLE')) {
} else {
$path = \CFile::GetPath($data[$this->code]);
$rsFile = \CFile::GetByID($data[$this->code]);
$file = $rsFile->Fetch();
if ($path) {
$html = '<a href="' . $path . '" >' . $file['FILE_NAME'] . ' (' . $file['FILE_DESCRIPTION'] . ')' . '</a>';
}
$row->AddViewField($this->code, $html);
}
}
示例6: __get_file_array
function __get_file_array($id, &$res)
{
static $arFilesCache = array();
if (!array_key_exists($id, $arFilesCache)) {
$db_res = CFile::GetByID($id);
$arFilesCache[$id] = $db_res->GetNext();
$arFilesCache[$id]["FILE_ARRAY"] = array();
__parse_file_size($arFilesCache[$id]["FILE_ARRAY"], $arFilesCache[$id]);
}
if (!array_key_exists($id, $arFilesCache)) {
$res = $arFilesCache[$id];
return true;
}
return false;
}
示例7: getAvatar
public static function getAvatar($uid = false)
{
global $USER;
if ($uid === false) {
$uid = $USER->GetID();
}
$rsUser = CUser::GetByID($uid);
$arResult = $rsUser->GetNext(false);
if (!empty($arResult) && !empty($arResult['PERSONAL_PHOTO'])) {
$db_img = CFile::GetByID($arResult['PERSONAL_PHOTO']);
$db_img_arr = $db_img->Fetch();
if (!empty($db_img_arr)) {
$strImageStorePath = COption::GetOptionString('main', 'upload_dir', 'upload');
$sImagePath = '/' . $strImageStorePath . '/' . $db_img_arr['SUBDIR'] . '/' . $db_img_arr['FILE_NAME'];
$sImagePath = str_replace('//', '/', $sImagePath);
return $sImagePath;
}
}
return false;
}
示例8: getFileData
/**
* Возвращает информацию о файле
*
* @param int|array $fid ID файла, либо массив ID файлов
* @return array - данные информация о файле
*/
public static function getFileData($fid)
{
if (!isset($fid)) {
return;
}
if (is_array($fid)) {
$rsFile = CFile::GetList(array(), array("@ID" => implode(",", $fid)));
} else {
$rsFile = CFile::GetByID($fid);
}
$ret = array();
while ($ifile = $rsFile->Fetch()) {
$ret[$ifile['ID']] = array("SRC" => P_UPLOAD . $ifile["SUBDIR"] . "/" . $ifile['FILE_NAME'], "WIDTH" => $ifile["WIDTH"], "HEIGHT" => $ifile["HEIGHT"], "DATA" => $ifile);
}
if (is_array($fid)) {
return $ret;
} else {
return $ret[$fid];
}
}
示例9: getAvatar
static function getAvatar($uid = false)
{
global $USER;
if ($uid === false) {
$uid = $USER->GetID();
}
$rsUser = CUser::GetByID($uid);
$arResult = $rsUser->GetNext(false);
if (!empty($arResult) && !empty($arResult["PERSONAL_PHOTO"])) {
$db_img = CFile::GetByID($arResult["PERSONAL_PHOTO"]);
$db_img_arr = $db_img->Fetch();
if (!empty($db_img_arr)) {
$strImageStorePath = COption::GetOptionString("main", "upload_dir", "upload");
$sImagePath = "/" . $strImageStorePath . "/" . $db_img_arr["SUBDIR"] . "/" . $db_img_arr["FILE_NAME"];
$sImagePath = str_replace("//", "/", $sImagePath);
return $sImagePath;
}
}
return false;
}
示例10: Edit
public static function Edit($Params)
{
global $DB;
$source_id = false;
$arFields = $Params['arFields'];
$bNew = !isset($arFields['ID']) || $arFields['ID'] <= 0;
$bFile_FD = $Params['path'] && strlen($Params['path']) > 0;
$bFile_PC = $Params['file'] && strlen($Params['file']['name']) > 0 && $Params['file']['size'] > 0;
$io = CBXVirtualIo::GetInstance();
if ($bFile_FD || $bFile_PC) {
if ($bFile_FD) {
$DocRoot = CSite::GetSiteDocRoot(false);
$tmp_name = $DocRoot . $Params['path'];
if ($io->FileExists($tmp_name)) {
$flTmp = $io->GetFile($tmp_name);
$file_name = substr($Params['path'], strrpos($Params['path'], '/') + 1);
$arFile = array("name" => $file_name, "size" => $flTmp->GetFileSize(), "tmp_name" => $tmp_name, "type" => CFile::IsImage($file_name) ? 'image' : 'file');
}
} else {
if ($bFile_PC) {
$arFile = $Params['file'];
}
}
if (!CMedialib::CheckFileExtention($arFile["name"])) {
return false;
}
if (!$bNew) {
$arFile["old_file"] = CMedialibItem::GetSourceId($arFields['ID']);
$arFile["del"] = "Y";
}
// Resizing Image
if (CFile::IsImage($arFile["name"])) {
$arSize = array('width' => COption::GetOptionInt('fileman', "ml_max_width", 1024), 'height' => COption::GetOptionInt('fileman', "ml_max_height", 1024));
$res = CFile::ResizeImage($arFile, $arSize);
}
$arFile["MODULE_ID"] = "fileman";
$source_id = CFile::SaveFile($arFile, "medialibrary");
if ($source_id) {
$r = CFile::GetByID($source_id);
if ($arFile = $r->Fetch()) {
if (CFile::IsImage($arFile['FILE_NAME'])) {
CMedialibItem::GenerateThumbnail($arFile, array('width' => COption::GetOptionInt('fileman', "ml_thumb_width", 140), 'height' => COption::GetOptionInt('fileman', "ml_thumb_height", 105)));
}
$arFile['PATH'] = CMedialibItem::GetFullPath($arFile);
}
}
}
// TODO: Add error handling
if ($bNew && !$source_id) {
return false;
}
// 2. Add to b_medialib_item
if (!isset($arFields['~DATE_UPDATE'])) {
$arFields['~DATE_UPDATE'] = $DB->CurrentTimeFunction();
}
if (!CMedialibItem::CheckFields($arFields)) {
return false;
}
if (CModule::IncludeModule("search")) {
$arStem = stemming($arFields['NAME'] . ' ' . $arFields['DESCRIPTION'] . ' ' . $arFields['KEYWORDS'], LANGUAGE_ID);
if (count($arStem) > 0) {
$arFields['SEARCHABLE_CONTENT'] = '{' . implode('}{', array_keys($arStem)) . '}';
} else {
$arFields['SEARCHABLE_CONTENT'] = '';
}
}
if ($bNew) {
unset($arFields['ID']);
$arFields['SOURCE_ID'] = $source_id;
$arFields['~DATE_CREATE'] = $arFields['~DATE_UPDATE'];
$arFields['ITEM_TYPE'] = '';
$ID = CDatabase::Add("b_medialib_item", $arFields, array("DESCRIPTION", "SEARCHABLE_CONTENT"));
} else {
if ($source_id) {
$arFields['SOURCE_ID'] = $source_id;
}
$ID = $arFields['ID'];
unset($arFields['ID']);
$strUpdate = $DB->PrepareUpdate("b_medialib_item", $arFields);
$strSql = "UPDATE b_medialib_item SET " . $strUpdate . " WHERE ID=" . IntVal($ID);
$DB->QueryBind($strSql, array("DESCRIPTION" => $arFields["DESCRIPTION"], "SEARCHABLE_CONTENT" => $arFields["SEARCHABLE_CONTENT"]), false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
}
// 3. Set fields to b_medialib_collection_item
if (!$bNew) {
$strSql = "DELETE FROM b_medialib_collection_item WHERE ITEM_ID=" . IntVal($ID);
$DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
}
$strCollections = "0";
for ($i = 0, $l = count($Params['arCollections']); $i < $l; $i++) {
$strCollections .= "," . IntVal($Params['arCollections'][$i]);
}
$strSql = "INSERT INTO b_medialib_collection_item(ITEM_ID, COLLECTION_ID) " . "SELECT " . intVal($ID) . ", ID " . "FROM b_medialib_collection " . "WHERE ID in (" . $strCollections . ")";
$res = $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
if (!$arFields['ID']) {
$arFields['ID'] = $ID;
}
if ($source_id) {
$arFields = array_merge($arFile, $arFields);
}
return $arFields;
//.........这里部分代码省略.........
示例11: array
<?php
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
die;
}
if (CModule::IncludeModule("catalog")) {
$ajaxResult = array();
if (IntVal($_REQUEST["PRODUCT_ID"]) > 0) {
$itemId = Add2BasketByProductID(IntVal($_REQUEST["PRODUCT_ID"]));
if ($itemId !== false) {
$arInfo = CIBlockElement::GetByID(IntVal($_REQUEST["PRODUCT_ID"]))->GetNext();
$strImageStorePath = COption::GetOptionString("main", "upload_dir", "upload");
$imageId = empty($arInfo["DETAIL_PICTURE"]) ? $arInfo["PREVIEW_PICTURE"] : $arInfo["DETAIL_PICTURE"];
if (!empty($imageId)) {
$sPath = CFile::GetByID($imageId)->GetNext();
$sPath = "/" . $strImageStorePath . "/" . $sPath["SUBDIR"] . "/" . $sPath["FILE_NAME"];
} else {
$sPath = "";
}
$ajaxResult["MSG"]["NAME"] = $arInfo["NAME"];
$ajaxResult["MSG"]["URL"] = $arInfo["DETAIL_PAGE_URL"];
$ajaxResult["MSG"]["IMG"] = $sPath;
} else {
$ajaxResult["MSG"] = "Ошибка добавления товара в корзину";
}
echo json_encode($ajaxResult);
}
}
示例12: array
$bGannt = (bool) $_POST['bGannt'];
}
// Override CHECK_PERMISSIONS, if it was given in $_POST['filter']
$arFilter['CHECK_PERMISSIONS'] = 'Y';
$rsTasks = CTasks::GetList($arOrder, $arFilter);
$arTasks = array();
$arTasksIDs = array();
$arViewed = array();
while ($task = $rsTasks->GetNext()) {
$arTasks[$task["ID"]] = $task;
$arTasksIDs[] = $task["ID"];
$arViewed[$task["ID"]] = $task["VIEWED_DATE"] ? $task["VIEWED_DATE"] : $task["CREATED_DATE"];
$rsTaskFiles = CTaskFiles::GetList(array(), array("TASK_ID" => $task["ID"]));
$task["FILES"] = array();
while ($arTaskFile = $rsTaskFiles->Fetch()) {
$rsFile = CFile::GetByID($arTaskFile["FILE_ID"]);
if ($arFile = $rsFile->Fetch()) {
$task["FILES"][] = $arFile;
}
}
$arTasks[$task["ID"]] = $task;
}
unset($arFilter["PARENT_ID"]);
$rsChildrenCount = CTasks::GetChildrenCount($arFilter, $arTasksIDs);
if ($rsChildrenCount) {
while ($arChildrens = $rsChildrenCount->Fetch()) {
$arChildrenCount["PARENT_" . $arChildrens["PARENT_ID"]] = $arChildrens["CNT"];
}
}
$arUpdatesCount = CTasks::GetUpdatesCount($arViewed);
$APPLICATION->RestartBuffer();
示例13: Array
COption::SetOptionString("eshop", "shopEmail", $shopEmail, false, WIZARD_SITE_ID);
$siteName = $wizard->GetVar("siteName");
COption::SetOptionString("eshop", "siteName", $siteName, false, WIZARD_SITE_ID);
$obSite = new CSite;
$obSite->Update(WIZARD_SITE_ID, Array(
"EMAIL" => $shopEmail,
"SITE_NAME" => $siteName,
"SERVER_NAME" => $_SERVER["SERVER_NAME"],
));
if(strlen($siteStamp)>0)
{
if(IntVal($siteStamp) > 0)
{
$ff = CFile::GetByID($siteStamp);
if($zr = $ff->Fetch())
{
$strOldFile = str_replace("//", "/", WIZARD_SITE_ROOT_PATH."/".(COption::GetOptionString("main", "upload_dir", "upload"))."/".$zr["SUBDIR"]."/".$zr["FILE_NAME"]);
@copy($strOldFile, WIZARD_SITE_PATH."include/stamp.gif");
CFile::Delete($zr["ID"]);
$siteStamp = WIZARD_SITE_DIR."include/stamp.gif";
COption::SetOptionString("eshop", "siteStamp", $siteStamp, false, WIZARD_SITE_ID);
}
}
}
else
{
$siteStamp = "/bitrix/templates/".WIZARD_TEMPLATE_ID."_".WIZARD_THEME_ID."/images/pechat.gif";
}
示例14: GetFieldInputValuePrintable
public static function GetFieldInputValuePrintable($documentType, $arFieldType, $fieldValue)
{
$result = $fieldValue;
switch ($arFieldType['Type']) {
case "user":
$result = CBPHelper::UsersArrayToString($fieldValue, null, $documentType);
break;
case "bool":
if (is_array($fieldValue)) {
$result = array();
foreach ($fieldValue as $r) {
$result[] = strtoupper($r) == "Y" ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO");
}
} else {
$result = strtoupper($fieldValue) == "Y" ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO");
}
break;
case "file":
if (is_array($fieldValue)) {
$result = array();
foreach ($fieldValue as $r) {
$r = intval($r);
$dbImg = CFile::GetByID($r);
if ($arImg = $dbImg->Fetch()) {
$result[] = "[url=/bitrix/tools/bizproc_show_file.php?f=" . htmlspecialcharsbx($arImg["FILE_NAME"]) . "&i=" . $r . "]" . htmlspecialcharsbx($arImg["ORIGINAL_NAME"]) . "[/url]";
}
}
} else {
$fieldValue = intval($fieldValue);
$dbImg = CFile::GetByID($fieldValue);
if ($arImg = $dbImg->Fetch()) {
$result = "[url=/bitrix/tools/bizproc_show_file.php?f=" . htmlspecialcharsbx($arImg["FILE_NAME"]) . "&i=" . $fieldValue . "]" . htmlspecialcharsbx($arImg["ORIGINAL_NAME"]) . "[/url]";
}
}
break;
case "select":
if (isset($arFieldType["Options"][$fieldValue])) {
$result = $arFieldType["Options"][$fieldValue];
}
break;
}
return $result;
}
示例15: GetFieldInputValuePrintable
function GetFieldInputValuePrintable($documentType, $arFieldType, $fieldValue)
{
if ($storage = self::needProxyToDiskByDocType($documentType)) {
return self::proxyToDisk(__FUNCTION__, array(\Bitrix\Disk\BizProcDocumentCompatible::generateDocumentType($storage->getId()), $arFieldType, $fieldValue));
}
$result = $fieldValue;
switch ($arFieldType['Type']) {
case "user":
if (!is_array($fieldValue)) {
$fieldValue = array($fieldValue);
}
$result = CBPHelper::UsersArrayToString($fieldValue, null, array("webdav", "CIBlockDocumentWebdavSocnet", $documentType));
break;
case "bool":
if (is_array($fieldValue)) {
$result = array();
foreach ($fieldValue as $r) {
$result[] = strtoupper($r) != "N" && !empty($r) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO");
}
} else {
$result = strtoupper($fieldValue) != "N" && !empty($fieldValue) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO");
}
break;
case "file":
if (is_array($fieldValue)) {
$result = array();
foreach ($fieldValue as $r) {
$r = intval($r);
$dbImg = CFile::GetByID($r);
if ($arImg = $dbImg->Fetch()) {
$result[] = "[url=/bitrix/tools/bizproc_show_file.php?f=" . urlencode($arImg["FILE_NAME"]) . "&i=" . $r . "]" . htmlspecialcharsbx($arImg["ORIGINAL_NAME"]) . "[/url]";
}
}
} else {
$fieldValue = intval($fieldValue);
$dbImg = CFile::GetByID($fieldValue);
if ($arImg = $dbImg->Fetch()) {
$result = "[url=/bitrix/tools/bizproc_show_file.php?f=" . urlencode($arImg["FILE_NAME"]) . "&i=" . $fieldValue . "]" . htmlspecialcharsbx($arImg["ORIGINAL_NAME"]) . "[/url]";
}
}
break;
case "select":
if (is_array($arFieldType["Options"])) {
if (is_array($fieldValue)) {
$result = array();
foreach ($fieldValue as $r) {
if (array_key_exists($r, $arFieldType["Options"])) {
$result[] = $arFieldType["Options"][$r];
}
}
} else {
if (array_key_exists($fieldValue, $arFieldType["Options"])) {
$result = $arFieldType["Options"][$fieldValue];
}
}
}
break;
}
if (strpos($arFieldType['Type'], ":") !== false) {
$arCustomType = CIBlockProperty::GetUserType(substr($arFieldType['Type'], 2));
if (array_key_exists("GetPublicViewHTML", $arCustomType)) {
if (is_array($fieldValue) && !CBPHelper::IsAssociativeArray($fieldValue)) {
$result = array();
foreach ($fieldValue as $value) {
$r = call_user_func_array($arCustomType["GetPublicViewHTML"], array(array("LINK_IBLOCK_ID" => $arFieldType["Options"]), array("VALUE" => $value), ""));
$result[] = HTMLToTxt($r);
}
} else {
$result = call_user_func_array($arCustomType["GetPublicViewHTML"], array(array("LINK_IBLOCK_ID" => $arFieldType["Options"]), array("VALUE" => $fieldValue), ""));
$result = HTMLToTxt($result);
}
}
}
return $result;
}