本文整理汇总了PHP中CFile::UpdateDesc方法的典型用法代码示例。如果您正苦于以下问题:PHP CFile::UpdateDesc方法的具体用法?PHP CFile::UpdateDesc怎么用?PHP CFile::UpdateDesc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFile
的用法示例。
在下文中一共展示了CFile::UpdateDesc方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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 (array_key_exists("content", $arFile)) {
if (!array_key_exists("size", $arFile)) {
$arFile["size"] = CUtil::BinStrlen($arFile["content"]);
}
} else {
$arFile["size"] = filesize($arFile["tmp_name"]);
}
$arFile["ORIGINAL_NAME"] = $strFileName;
$io = CBXVirtualIo::GetInstance();
if (self::validateFile($strFileName, $arFile, $bForceMD5) !== "") {
return false;
}
$upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
if ($arFile["type"] == "image/pjpeg" || $arFile["type"] == "image/jpg") {
$arFile["type"] = "image/jpeg";
}
//.jpe is not image type on many systems
if (strtolower(GetFileExtension($strFileName)) == "jpe") {
$strFileName = substr($strFileName, 0, -4) . ".jpg";
}
$bExternalStorage = false;
foreach (GetModuleEvents("main", "OnFileSave", true) as $arEvent) {
if (ExecuteModuleEventEx($arEvent, array(&$arFile, $strFileName, $strSavePath, $bForceMD5, $bSkipExt))) {
$bExternalStorage = true;
break;
}
}
if (!$bExternalStorage) {
$newName = '';
if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") {
$dir_add = '';
$i = 0;
while (true) {
$dir_add = substr(md5(uniqid(mt_rand(), 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 . "/";
}
$newName = $strFileName;
} else {
$strFileExt = $bSkipExt == true ? '' : strrchr($strFileName, ".");
while (true) {
$newName = md5(uniqid(mt_rand(), true)) . $strFileExt;
if (substr($strSavePath, -1, 1) != "/") {
$strSavePath .= "/" . substr($newName, 0, 3);
} else {
$strSavePath .= substr($newName, 0, 3) . "/";
}
if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $newName)) {
break;
}
}
}
$arFile["SUBDIR"] = $strSavePath;
$arFile["FILE_NAME"] = $newName;
$strDirName = $_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/";
$strDbFileNameX = $strDirName . $newName;
$strPhysicalFileNameX = $io->GetPhysicalName($strDbFileNameX);
CheckDirPath($strDirName);
if (is_set($arFile, "content")) {
$f = fopen($strPhysicalFileNameX, "ab");
if (!$f) {
return false;
//.........这里部分代码省略.........
示例2: SetPropertyValues
//.........这里部分代码省略.........
}
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
$strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
}
} else {
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
if ($prop["PROPERTY_TYPE"] == "N") {
$val = CIBlock::roundDB($val);
}
$strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "='" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=" . ($val_desc !== false ? "'" . $DB->ForSQL($val_desc, 255) . "'" : "null") . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID;
} else {
$strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET \tVALUE='" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t\t,VALUE_NUM=" . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"];
}
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
$strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
}
}
} elseif ($prop["PROPERTY_TYPE"] == "F") {
if (is_array($val)) {
if (strlen($val["del"]) > 0) {
$val = "NULL";
} else {
$val["MODULE_ID"] = "iblock";
if ($val_desc !== false) {
$val["description"] = $val_desc;
}
if ($val_desc !== false && strlen($val["name"]) <= 0) {
//update description only
if ($res["VALUE"] > 0) {
CFile::UpdateDesc($res["VALUE"], $val_desc);
}
$val = false;
} else {
//register new file
$val = CFile::SaveFile($val, "iblock");
}
}
}
if ($val == "NULL") {
CIBLockElement::DeleteFile($res["VALUE"], $ELEMENT_ID, "PROPERTY", -1, $prop["IBLOCK_ID"]);
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
$strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID;
} else {
$strSql = "DELETE FROM " . $strTable . " WHERE ID=" . $res["ID"];
}
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
$strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
}
} elseif (IntVal($val) > 0) {
if (intval($val) != $res["VALUE"]) {
CIBLockElement::DeleteFile($res["VALUE"], $ELEMENT_ID, "PROPERTY", -1, $prop["IBLOCK_ID"]);
}
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
$strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "='" . intval($val) . "'\n\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION_" . $prop["ID"] . "='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID;
} else {
$strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET \tVALUE='" . intval($val) . "'\n\t\t\t\t\t\t\t\t\t\t,VALUE_NUM='" . intval($val) . "'\n\t\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"];
}
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
$strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
示例3: SetPropertyValues
//.........这里部分代码省略.........
foreach (array_reverse($orderedPROP, true) as $propertyValueId => $val) {
if (intval($propertyValueId) > 0) {
break;
}
$tailStart = $propertyValueId;
}
$prevId = 0;
foreach ($orderedPROP as $propertyValueId => $val) {
if ($propertyValueId === $tailStart) {
break;
}
if (intval($propertyValueId) < $prevId) {
$preserveID = array();
break;
}
$prevId = $propertyValueId;
}
}
//Write new values into database in specified order
foreach ($orderedPROP as $propertyValueId => $val) {
if (is_array($val) && !array_key_exists("tmp_name", $val)) {
$val_desc = $val["DESCRIPTION"];
$val = $val["VALUE"];
} else {
$val_desc = false;
}
if (is_array($val)) {
$val["MODULE_ID"] = "iblock";
if ($val_desc !== false) {
$val["description"] = $val_desc;
}
$val = CFile::SaveFile($val, "iblock");
} elseif ($val > 0 && $val_desc !== false) {
CFile::UpdateDesc($val, $val_desc);
}
if (intval($val) <= 0) {
continue;
}
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
$DB->Query($s = "\n\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . " = '" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc) . "\n\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t");
} elseif (array_key_exists($propertyValueId, $preserveID)) {
$DB->Query("\n\t\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t\t(ID, IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM" . ($val_desc !== false ? ", DESCRIPTION" : "") . ")\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t" . $preserveID[$propertyValueId] . "\n\t\t\t\t\t\t\t\t," . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t,P.ID\n\t\t\t\t\t\t\t\t,'" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t," . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ", '" . $DB->ForSQL($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tID = " . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t");
} else {
$DB->Query("\n\t\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM" . ($val_desc !== false ? ", DESCRIPTION" : "") . ")\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t,P.ID\n\t\t\t\t\t\t\t\t,'" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t," . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ", '" . $DB->ForSQL($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tID = " . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t");
}
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
$arV2ClearCache[$prop["ID"]] = "PROPERTY_" . $prop["ID"] . " = NULL" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]);
}
if ($prop["MULTIPLE"] != "Y") {
break;
}
}
//foreach($PROP as $value)
} else {
if ($arDBProps[$prop["ID"]]) {
foreach ($arDBProps[$prop["ID"]] as $res) {
$val = $PROP[$res["ID"]];
if (is_array($val)) {
$val_desc = $val["DESCRIPTION"];
$val = $val["VALUE"];
} else {
$val_desc = false;
}
if (strlen($val) <= 0) {
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
$DB->Query("\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . " = null\n\t\t\t\t\t\t\t\t\t\t" . self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"]) . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t");
示例4: processEditAction
/**
* {@inheritdoc}
*/
public function processEditAction()
{
parent::processEditAction();
if ($this->getSettings('MULTIPLE')) {
if ($this->getSettings('READONLY') === true) {
//удаляем все добавленные файлы в режиме только для чтения
foreach ($this->data[$this->code] as $key => $value) {
if (!is_array($value)) {
unset($this->data[$this->code][$key]);
}
}
return false;
}
if (class_exists('\\Bitrix\\Main\\UI\\FileInput', true) && $this->getSettings('IMAGE') === true) {
foreach ($this->data[$this->code] as $key => $value) {
if (is_array($value) && ($value['name'] || $value['tmp_name'])) {
$_FILES[$this->code]['name'][$key] = $value['name'];
$_FILES[$this->code]['type'][$key] = $value['type'];
$_FILES[$this->code]['tmp_name'][$key] = $value['tmp_name'];
$_FILES[$this->code]['error'][$key] = $value['error'];
$_FILES[$this->code]['size'][$key] = $value['size'];
unset($this->data[$this->code][$key]);
} else {
$_FILES[$this->code]['name'][$key] = '';
}
}
if (!count($this->data[$this->code])) {
unset($this->data[$this->code]);
}
}
if (!empty($_FILES[$this->getCode()])) {
foreach ($_FILES[$this->getCode()]['name'] as $key => $fileName) {
if (empty($fileName) || empty($_FILES[$this->getCode()]['tmp_name'][$key]) || !empty($_FILES[$this->getCode()]['error'][$key])) {
if (isset($_REQUEST[$this->getCode() . '_del'][$key])) {
if (is_array($this->data[$this->getCode()][$key]) && !empty($this->data[$this->getCode()][$key]['VALUE'])) {
\CFile::Delete(intval($this->data[$this->getCode()][$key]['VALUE']));
} else {
\CFile::Delete(intval($this->data[$this->getCode()][$key]));
}
unset($this->data[$this->getCode()][$key]);
} elseif ($this->data[$this->getCode()][$key]['VALUE']) {
\CFile::UpdateDesc($this->data[$this->getCode()][$key]['VALUE'], $_REQUEST[$this->getCode() . '_descr'][$key]);
}
continue;
} elseif (is_int($key)) {
//Удаляем старый файл при замене
if (is_array($this->data[$this->getCode()][$key]) && !empty($this->data[$this->getCode()][$key]['VALUE'])) {
\CFile::Delete(intval($this->data[$this->getCode()][$key]['VALUE']));
} else {
\CFile::Delete(intval($this->data[$this->getCode()][$key]));
}
}
$description = null;
if (isset($_REQUEST[$this->getCode() . '_descr'][$key])) {
$description = $_REQUEST[$this->getCode() . '_descr'][$key];
}
if (empty($this->data[$this->getCode()][$key])) {
unset($this->data[$this->getCode()][$key]);
}
$fileId = $this->saveFile($fileName, $_FILES[$this->getCode()]['tmp_name'][$key], false, $description);
if ($fileId) {
$this->data[$this->getCode()][$key] = array('VALUE' => $fileId);
} else {
$this->addError('DIGITALWAND_AH_FAIL_ADD_FILE', array('FILE_NAME' => $_FILES[$this->getCode()]['name'][$key]));
}
}
}
} else {
if (class_exists('\\Bitrix\\Main\\UI\\FileInput', true) && $this->getSettings('IMAGE') === true) {
if (is_array($this->data[$this->code . '_FILE']) && ($this->data[$this->code . '_FILE']['name'] || $this->data[$this->code . '_FILE']['tmp_name'])) {
$_FILES['FIELDS']['name'][$this->code . '_FILE'] = $this->data[$this->code . '_FILE']['name'];
$_FILES['FIELDS']['type'][$this->code . '_FILE'] = $this->data[$this->code . '_FILE']['type'];
$_FILES['FIELDS']['tmp_name'][$this->code . '_FILE'] = $this->data[$this->code . '_FILE']['tmp_name'];
$_FILES['FIELDS']['error'][$this->code . '_FILE'] = $this->data[$this->code . '_FILE']['error'];
$_FILES['FIELDS']['size'][$this->code . '_FILE'] = $this->data[$this->code . '_FILE']['size'];
}
}
unset($this->data[$this->code . '_FILE']);
if ($this->getSettings('READONLY') === true) {
return false;
}
if (empty($_FILES['FIELDS']['name'][$this->code . '_FILE']) || empty($_FILES['FIELDS']['tmp_name'][$this->code . '_FILE']) || !empty($_FILES['FIELDS']['error'][$this->code . '_FILE'])) {
if (isset($_REQUEST['FIELDS_del'][$this->code . '_FILE']) and $_REQUEST['FIELDS_del'][$this->code . '_FILE'] == 'Y') {
\CFile::Delete(intval($this->data[$this->code]));
$this->data[$this->code] = 0;
} elseif ($this->data[$this->code] && isset($_REQUEST['FIELDS_descr'][$this->code . '_FILE'])) {
\CFile::UpdateDesc($this->data[$this->code], $_REQUEST['FIELDS_descr'][$this->code . '_FILE']);
}
return false;
}
$description = null;
if (isset($_REQUEST['FIELDS_descr'][$this->code . '_FILE'])) {
$description = $_REQUEST['FIELDS_descr'][$this->code . '_FILE'];
}
$name = $_FILES['FIELDS']['name'][$this->code . '_FILE'];
$path = $_FILES['FIELDS']['tmp_name'][$this->code . '_FILE'];
$type = $_FILES['FIELDS']['type'][$this->code . '_FILE'];
//.........这里部分代码省略.........
示例5: SetPropertyValues
//.........这里部分代码省略.........
}
} //foreach($arDBProps[$prop["ID"]] as $res)
}
//Write new values into database in specified order
foreach ($orderedPROP as $val)
{
if(
is_array($val)
&& !array_key_exists("tmp_name", $val)
)
{
$val_desc = $val["DESCRIPTION"];
$val = $val["VALUE"];
}
else
{
$val_desc = false;
}
if (is_array($val))
{
$val["MODULE_ID"] = "iblock";
if ($val_desc !== false)
$val["description"] = $val_desc;
$val = CFile::SaveFile($val, "iblock");
}
elseif (
$val > 0
&& $val_desc !== false
)
{
CFile::UpdateDesc($val, $val_desc);
}
if (intval($val) <= 0)
continue;
if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N")
{
$DB->Query($s="
UPDATE b_iblock_element_prop_s".$prop["IBLOCK_ID"]."
SET
PROPERTY_".$prop["ID"]." = '".$DB->ForSql($val)."'
".self::__GetDescriptionUpdateSql($prop["IBLOCK_ID"], $prop["ID"], $val_desc)."
WHERE IBLOCK_ELEMENT_ID=".$ELEMENT_ID."
");
}
else
{
$DB->Query("
INSERT INTO ".$strTable."
(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM".($val_desc!==false?", DESCRIPTION":"").")
SELECT
".$ELEMENT_ID."
,P.ID
,'".$DB->ForSql($val)."'
,".CIBlock::roundDB($val)."
".($val_desc!==false?", '".$DB->ForSQL($val_desc, 255)."'":"")."
FROM
b_iblock_property P
WHERE
ID = ".IntVal($prop["ID"])."
");
}
示例6: 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(is_set($arFile, "description") && intval($arFile["old_file"])>0)
CFile::UpdateDesc($arFile["old_file"], $arFile["description"]);
return false;
}
if(is_set($arFile, "content") && !is_set($arFile, "size"))
$arFile["size"] = CUtil::BinStrlen($arFile["content"]);
else
$arFile["size"] = filesize($arFile["tmp_name"]);
/****************************** QUOTA ******************************/
if (COption::GetOptionInt("main", "disk_space") > 0)
{
$quota = new CDiskQuota();
if (!$quota->checkDiskQuota($arFile))
return false;
}
/****************************** QUOTA ******************************/
$arFile["ORIGINAL_NAME"] = $strFileName;
$io = CBXVirtualIo::GetInstance();
if($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y")
{
if(COption::GetOptionString("main", "translit_original_file_name", "N") == "Y")
$strFileName = CUtil::translit($strFileName, LANGUAGE_ID, array("max_len"=>1024, "safe_chars"=>"."));
if(COption::GetOptionString("main", "convert_original_file_name", "Y") == "Y")
$strFileName = $io->RandomizeInvalidFilename($strFileName);
}
if(!$io->ValidateFilenameString($strFileName))
return false;
//check for double extension vulnerability
$strFileName = RemoveScriptExtension($strFileName);
if($strFileName == '')
return false;
if(strlen($strFileName) > 255)
return false;
//check .htaccess etc.
if(IsFileUnsafe($strFileName))
return false;
//nginx returns octet-stream for .jpg
if(GetFileNameWithoutExtension($strFileName) == '')
return false;
$upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
if($arFile["type"]=="image/pjpeg" || $arFile["type"]=="image/jpg")
$arFile["type"]="image/jpeg";
//.jpe is not image type on many systems
if(strtolower(GetFileExtension($strFileName)) == "jpe")
$strFileName = substr($strFileName, 0, -4).".jpg";
$bExternalStorage = false;
foreach(GetModuleEvents("main", "OnFileSave", true) as $arEvent)
{
if(ExecuteModuleEventEx($arEvent, array(&$arFile, $strFileName, $strSavePath, $bForceMD5, $bSkipExt)))
{
$bExternalStorage = true;
break;
}
}
if(!$bExternalStorage)
{
$newName = '';
if($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N")=="Y")
{
$dir_add = '';
$i=0;
while(true)
{
$dir_add = substr(md5(uniqid(mt_rand(), 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);
//.........这里部分代码省略.........
示例7: 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")) {
//.........这里部分代码省略.........