本文整理汇总了PHP中CFile类的典型用法代码示例。如果您正苦于以下问题:PHP CFile类的具体用法?PHP CFile怎么用?PHP CFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveFileAction
function saveFileAction()
{
if (!($img = $_FILES['Filedata'])) {
print json_encode(array('success' => false, 'text' => "Не получены данные", 'debug' => $_FILES['Filedata']));
return false;
}
if (front::$_req["type"] == "img") {
list($width, $height, $type, $attr) = getimagesize($img['tmp_name']);
$ext = array('gif', 'jpeg', 'png');
$ext_format = array('gif' => 1, 'jpeg' => 2, 'png' => 3);
if ($type < 1 || $type > 3) {
print json_encode(array('success' => false, 'text' => "Формат не поддерживается", 'debug' => $_FILES['Filedata']));
return false;
}
if (front::$_req["width"] > 0 && $width > front::$_req["width"] || front::$_req["height"] > 0 && $height > front::$_req["height"]) {
print json_encode(array('success' => false, 'text' => "Слишком большое разрешение", 'debug' => $_FILES['Filedata']));
return false;
}
}
$b_file = new CFile($_FILES['Filedata']);
$b_file->max_size = 1048576;
$b_file->server_root = 1;
$f_name = $b_file->MoveUploadedFile("temp/");
echo json_encode(array("success" => true, "id" => $f_name, "path" => WDCPREFIX . "/temp/" . $f_name));
}
示例2: executeComponent
function executeComponent()
{
$arFilter = array('IBLOCK_ID' => $this->arParams['IBLOCK_ID'], 'ACTIVE' => 'Y');
if (true || $this->StartResultCache()) {
$CIBlockElement = new CIBlockElement();
$CFile = new \CFile();
$aElts = array();
$eltsSelectFields = array_merge(array('ID', 'NAME', 'CODE', 'PREVIEW_PICTURE', 'DETAIL_PICTURE', 'DETAIL_PAGE_URL'), $this->getIBlockProperties($this->arParams['IBLOCK_ID']));
$rsElts = $CIBlockElement->GetList(array('SORT' => 'asc', 'date_active_from' => 'DESC'), $arFilter, false, false, array('ID', 'NAME'));
if (intval($rsElts->SelectedRowsCount())) {
while ($arElt = $rsElts->Fetch()) {
$aElts[] = array('ID' => $arElt['ID'], 'NAME' => $arElt['NAME']);
}
$arElt = $CIBlockElement->GetList(array('SORT' => 'asc', 'ID' => 'DESC'), array_merge($arFilter, array('ID' => $aElts[0]['ID'])), false, false, $eltsSelectFields)->GetNext();
if ($arElt['DETAIL_PICTURE']) {
$arElt['DETAIL_PICTURE'] = $CFile->GetPath($arElt['DETAIL_PICTURE']);
} elseif ($arElt['PREVIEW_PICTURE']) {
$arElt['DETAIL_PICTURE'] = $CFile->GetPath($arElt['PREVIEW_PICTURE']);
}
$arPrice = CPrice::GetList(array(), array("PRODUCT_ID" => $arElt['ID']))->Fetch();
$arElt['PRICE'] = $arPrice['PRICE'];
$this->arResult['ITEMS'] = $aElts;
$this->arResult['ITEM'] = $arElt;
$this->IncludeComponentTemplate();
}
}
}
示例3: process_event
public function process_event(&$event)
{
if ($event->type == 'check' && $event->data['id']) {
$file = new CFile($event->data['id']);
$file->antivirus();
if ($file->virus == 0) {
$status = 'Clear.';
} else {
if ($file->virus == 1) {
$status = 'Infected. ' . $file->virusName . '.';
} else {
if ($file->virus == 2) {
$status = 'Skipped by archive restrictions.';
} else {
if ($file->virus == 16) {
$status = 'No need check. Skipped.';
} else {
$status = 'Error.';
}
}
}
}
$this->log->notice("File \"{$file->name}\" ({$file->table}) ({$file->id}). {$status}");
}
return PGQ_EVENT_OK;
}
示例4: saveFileAction
public function saveFileAction()
{
//die("1ssss");
if (!($img = $_FILES['Filedata'])) {
print json_encode(array('success' => false, 'text' => 'Не получены данные', 'debug' => $_FILES['Filedata']));
return false;
}
if (front::$_req['type'] == 'img') {
list($width, $height, $type, $attr) = getimagesize($img['tmp_name']);
$ext = array('gif', 'jpeg', 'png');
$ext_format = array('gif' => 1, 'jpeg' => 2, 'png' => 3);
if ($type < 1 || $type > 3) {
// print(json_encode(array ('success' => false, 'text'=>"Формат не поддерживается", 'debug' => $_FILES['Filedata'])));
// return false;
}
if (front::$_req['width'] > 0 && $width > front::$_req['width'] || front::$_req['height'] > 0 && $height > front::$_req['height']) {
print json_encode(array('success' => false, 'text' => 'Слишком большое разрешение', 'debug' => $_FILES['Filedata']));
return false;
}
}
$b_file = new CFile($_FILES['Filedata']);
$b_file->max_size = 1048576;
$b_file->server_root = 1;
$f_name = $b_file->MoveUploadedFile('temp/');
echo json_encode(array('success' => true, 'id' => $f_name, 'path' => WDCPREFIX . '/temp/' . $f_name, 'name' => $_FILES['Filedata']['name']));
}
示例5: rotate
/**
*
*/
function rotate()
{
if (file_exists($this->_file) && filesize($this->_file) >= $this->_size * 1024 * 1024) {
// ,
// ,
//
$LockFileHandler = new CFile($this->_file . '.lock');
$LockFileHandler->open('w');
if (!$LockFileHandler->isError()) {
$LockFileHandler->lock(LOCK_EX);
}
// , ( )
// $renames array(exists_files, new_file)
// new_file , $renames
// .
// , $renames :
// array(
// array('/var/log/logfile', '/var/log/logfile.1'),
// array('/var/log/logfile.1', '/var/log/logfile.2'),
// array('/var/log/logfile.2', '/var/log/logfile.3'),
// )
// :
// 1. , /var/log/logfile.3 - , rename
// 2. !
$cnt = 1;
$renames = array();
$filename = $this->_file . '.' . $cnt;
$cnt++;
$renames[] = array($this->_file, $filename);
while (file_exists($filename)) {
$new_filename = $this->_file . '.' . $cnt;
$cnt++;
$renames[] = array($filename, $new_filename);
$filename = $new_filename;
}
// ,
$removes = array();
if (count($renames) > $this->_rotate) {
$removes = array_slice($renames, $this->_rotate);
$renames = array_slice($renames, 0, $this->_rotate);
}
//
foreach ($removes as $f) {
@unlink($f[0]);
}
//
$renames = array_reverse($renames);
foreach ($renames as $f) {
rename($f[0], $f[1]);
}
//
touch($this->_file);
$LockFileHandler->unlock();
$LockFileHandler->close();
}
}
示例6: Del
/**
* Удалить отзыв
*
* @param int $msg ID отзыва
* @param int $admin Является ли пользователь администратором 1 - да, 0 - нет (типа is_admin из stdf)
* @return array сообщение об ошибке
*/
function Del($msg, $admin = 0)
{
if (!$admin) {
return 0;
}
if ($ret = $GLOBALS['DB']->val("DELETE FROM sopinions WHERE (id = ?) RETURNING logo", $msg)) {
$file = new CFile();
$file->Delete(0, "about/opinions/", $ret);
}
return $DB->error;
}
示例7: index
/**
* parse file for indexing
* @todo convert to using the FileSystem methods
*/
public function index(CFile $file)
{
/* Workaround for indexing large files:
** Based on the value defined in config data,
** files with file_size greater than specified limit
** are not indexed for searching.
** Negative value :<=> no filesize limit
*/
$index_max_file_size = w2PgetConfig('index_max_file_size', 0);
if ($file->file_size > 0 && ($index_max_file_size < 0 || (int) $file->file_size <= $index_max_file_size * 1024)) {
// get the parser application
$parser = w2PgetConfig('parser_' . $file->file_type);
if (!$parser) {
$parser = w2PgetConfig('parser_default');
}
if (!$parser) {
return false;
}
// buffer the file
$file->_filepath = W2P_BASE_DIR . '/files/' . $file->file_project . '/' . $file->file_real_filename;
if (file_exists($file->_filepath)) {
$fp = fopen($file->_filepath, 'rb');
$x = fread($fp, $file->file_size);
fclose($fp);
$ignore = w2PgetSysVal('FileIndexIgnoreWords');
$ignore = $ignore['FileIndexIgnoreWords'];
$ignore = explode(',', $ignore);
$x = strtolower($x);
$x = preg_replace("/[^A-Za-z0-9 ]/", "", $x);
foreach ($ignore as $ignoreWord) {
$x = str_replace(" {$ignoreWord} ", ' ', $x);
}
$x = str_replace(' ', ' ', $x);
$words = explode(' ', $x);
foreach ($words as $index => $word) {
if ('' == trim($word)) {
continue;
}
$q = $this->query;
$q->addTable('files_index');
$q->addInsert('file_id', $file->file_id);
$q->addInsert('word', $word);
$q->addInsert('word_placement', $index);
$q->exec();
$q->clear();
}
} else {
//TODO: if the file doesn't exist.. should we delete the db record?
}
}
$file->file_indexed = 1;
$file->store();
return count($words);
}
示例8: delete
public function delete(CFile $file)
{
$file->file_project = (int) $file->file_project;
if ('' == $file->file_real_filename || !file_exists(W2P_BASE_DIR . '/files/' . $file->file_project . '/' . $file->file_real_filename)) {
return true;
}
if ($file->canDelete()) {
return @unlink(W2P_BASE_DIR . '/files/' . $file->file_project . '/' . $file->file_real_filename);
}
return false;
}
示例9: countUnsentDocItems
/**
* Count unsent document items
*
* @return void
*/
function countUnsentDocItems()
{
$where["file_category_id"] = "= '{$this->_id}'";
$where["etat_envoi"] = "!= 'oui'";
$where["object_id"] = "IS NOT NULL";
$file = new CFile();
$this->_count_unsent_files = $file->countList($where);
$document = new CCompteRendu();
$this->_count_unsent_documents = $document->countList($where);
$this->_count_unsent_doc_items = $this->_count_unsent_documents + $this->_count_unsent_files;
}
示例10: saveFile
/**
* Сохраняем документ на сайте.
*
* @return \CFile
*/
public function saveFile()
{
$login = 'admin';
$content = $this->getOutput();
$file = new CFile();
$file->path = 'users/' . substr($login, 0, 2) . "/{$login}/upload/";
$file->name = basename($file->secure_tmpname($file->path, '.odt'));
$file->size = strlen($content);
if ($file->putContent($file->path . $file->name, $content)) {
return $file;
}
}
示例11: viewattachExternal
/**
* Выводит икону и задданный внешний URL для определенного файла
*
* @param string $ulogin Логин пользователя
* @param string $filename Имя файла
* @param string $dir Папка файла
* @param string $url Ссылка на файл
* @param integer $bigtext Вместо иконкки будет большой текст расширения файла(TXT, PDF, etc...) если переменная принимает значение 1
* @return string HTML-code
*/
function viewattachExternal($ulogin, $filename, $dir, $url, $bigtext = 0)
{
$l_dir = substr($ulogin, 0, 2) . "/" . $ulogin;
$cfile = new CFile("users/{$l_dir}/" . $dir . "/" . $filename);
if (!$cfile->size) {
return "";
}
$ext = $cfile->getext($filename);
$ico = getICOFile($ext, true);
echo $ico;
$fsize = ConvertBtoMB($cfile->size);
return '<p><img src="/pda/images/mime/' . $ico . '.png" alt="' . $ext . '" width="18" height="16"> <a href="' . $url . '" target="_blank">Скачать</a> | ' . ucfirst($ext) . ', ' . $fsize . ' </p>';
}
示例12: deleteFiles
function deleteFiles($order_id, $types)
{
$types = !is_array($types) ? array($types) : $types;
$rows = CFile::selectFilesBySrc('file_reserves_order', $order_id);
if (!$rows) {
return 0;
}
foreach ($rows as $row) {
if (!in_array($row['doc_type'], $types)) {
continue;
}
$file = new CFile();
$file->Delete($row['id']);
}
}
示例13: editDoc
/**
* Редактировать документ.
*
* @param array $doc новые данные по документу.
* @param array $old_doc старые данные по документу.
*
* @return bool успешно?
*/
public function editDoc($doc, $old_doc)
{
$sql_data = $doc;
$sql_data['name'] = pg_escape_string(change_q_x($sql_data['name']));
$act_time = self::$docs_ss[$sql_data['status']][1];
$file_set = $doc['file_id'] ? ", file_id = {$doc['file_id']}" : '';
$sql_data['stage_id'] = $sql_data['stage_id'] ? (int) $sql_data['stage_id'] : 'NULL';
$sql = "\n UPDATE sbr_docs\n SET name = '{$sql_data['name']}',\n status = {$sql_data['status']},\n access_role = {$sql_data['access_role']},\n stage_id = {$sql_data['stage_id']},\n {$act_time} = COALESCE({$act_time}, now()),\n type = {$sql_data['type']}\n {$file_set}\n WHERE id = {$sql_data['id']}\n ";
$ok = $this->_eventQuery($sql);
if ($ok && $file_set) {
$cfile = new CFile();
$cfile->Delete(0, $old_doc['file_path'], $old_doc['file_name']);
}
return $ok;
}
示例14: loadData
private function loadData()
{
if (empty($this->arParams['PARAMS']['arUserField'])) {
return array();
}
$userId = $this->getUser()->getId();
$values = $this->arParams['PARAMS']['arUserField']['VALUE'];
if (!is_array($this->arParams['PARAMS']['arUserField']['VALUE'])) {
$values = array($values);
}
$urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();
$versions = array();
foreach ($values as $value) {
$attachedObjectId = (int) $value;
if ($attachedObjectId <= 0) {
continue;
}
/** @var \Bitrix\Disk\AttachedObject $attachedModel */
$attachedModel = \Bitrix\Disk\AttachedObject::loadById($attachedObjectId, array('VERSION.OBJECT'));
if (!$attachedModel) {
continue;
}
$version = $attachedModel->getVersion();
if (!$version) {
continue;
}
$extension = $version->getExtension();
$versions[] = array('ID' => $attachedModel->getId(), 'NAME' => $version->getName(), 'CONVERT_EXTENSION' => DocumentHandler::isNeedConvertExtension($extension), 'EDITABLE' => DocumentHandler::isEditable($extension), 'CAN_UPDATE' => $attachedModel->canUpdate($userId), 'FROM_EXTERNAL_SYSTEM' => $version->getObject()->getContentProvider() && $version->getObject()->getCreatedBy() == $userId, 'EXTENSION' => $extension, 'SIZE' => \CFile::formatSize($version->getSize()), 'HISTORY_URL' => $urlManager->getUrlUfController('history', array('attachedId' => $attachedModel->getId())), 'DOWNLOAD_URL' => $urlManager->getUrlUfController('download', array('attachedId' => $attachedModel->getId())), 'COPY_TO_ME_URL' => $urlManager->getUrlUfController('copyTome', array('attachedId' => $attachedModel->getId())), 'VIEW_URL' => $urlManager->getUrlToShowAttachedFileByService($attachedModel->getId(), 'gvdrive'), 'EDIT_URL' => $urlManager->getUrlToStartEditUfFileByService($attachedModel->getId(), 'gdrive'), 'GLOBAL_CONTENT_VERSION' => $version->getGlobalContentVersion(), 'ATTRIBUTES_FOR_VIEWER' => Ui\Viewer::getAttributesByAttachedObject($attachedModel, array('version' => $version->getGlobalContentVersion(), 'canUpdate' => $attachedModel->canUpdate($userId), 'showStorage' => false, 'externalId' => false, 'relativePath' => false)));
}
unset($value);
return $versions;
}
示例15: UnInstallDB
function UnInstallDB($arParams = array())
{
global $DB, $APPLICATION;
$errors = false;
if (array_key_exists("savedata", $arParams) && $arParams["savedata"] != "Y") {
$errors = $DB->RunSQLBatch($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/support/install/db/' . strtolower($DB->type) . '/uninstall.sql');
if (!is_array($errors)) {
@set_time_limit(600);
COption::RemoveOption('support');
$db_res = $DB->Query("SELECT ID FROM b_file WHERE MODULE_ID = 'support'");
while ($arRes = $db_res->Fetch()) {
CFile::Delete($arRes['ID']);
}
if ($arParams['admin'] == 'Y') {
$this->UnInstallEvents();
}
}
}
if (is_array($errors)) {
$APPLICATION->ThrowException(implode(' ', $errors));
return false;
}
CAgent::RemoveModuleAgents('support');
UnRegisterModuleDependences('mail', 'OnGetFilterList', 'support', 'CSupportEMail', 'OnGetFilterList');
UnRegisterModule('support');
return true;
}