當前位置: 首頁>>代碼示例>>PHP>>正文


PHP KunenaAttachmentHelper::getAvailableFilename方法代碼示例

本文整理匯總了PHP中KunenaAttachmentHelper::getAvailableFilename方法的典型用法代碼示例。如果您正苦於以下問題:PHP KunenaAttachmentHelper::getAvailableFilename方法的具體用法?PHP KunenaAttachmentHelper::getAvailableFilename怎麽用?PHP KunenaAttachmentHelper::getAvailableFilename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在KunenaAttachmentHelper的用法示例。


在下文中一共展示了KunenaAttachmentHelper::getAvailableFilename方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: saveFile

 /**
  * Set attachment file.
  *
  * Copies the attachment into proper location and makes sure that all the unset fields get properly assigned.
  *
  * @param  string  $source     Absolute path to the upcoming attachment.
  * @param  string  $basename   Filename without extension.
  * @param  string  $extension  File extension.
  * @param  bool    $unlink     Whether to delete the original file or not.
  * @param  bool    $overwrite  If not allowed, throw exception if the file exists.
  *
  * @return bool
  * @throws InvalidArgumentException
  * @throws RuntimeException
  *
  * @since  K4.0
  */
 public function saveFile($source, $basename = null, $extension = null, $unlink = false, $overwrite = false)
 {
     if (!is_file($source)) {
         throw new InvalidArgumentException(__CLASS__ . '::' . __METHOD__ . '(): Attachment file not found.');
     }
     // Hash, size and MIME are set during saving, so let's deal with all other variables.
     $this->userid = is_null($this->userid) ? KunenaUserHelper::getMyself() : $this->userid;
     $this->folder = is_null($this->folder) ? "media/kunena/attachments/{$this->userid}" : $this->folder;
     $this->protected = is_null($this->protected) ? (bool) KunenaConfig::getInstance()->attachment_protection : $this->protected;
     if (!$this->filename_real) {
         $this->filename_real = $this->filename;
     }
     if (!$this->filename || $this->filename == $this->filename_real) {
         if (!$basename || !$extension) {
             throw new InvalidArgumentException(__CLASS__ . '::' . __METHOD__ . '(): Parameters $basename or $extension not provided.');
         }
         // Find available filename.
         $this->filename = KunenaAttachmentHelper::getAvailableFilename($this->folder, $basename, $extension, $this->protected);
     }
     // Create target directory if it does not exist.
     if (!KunenaFolder::exists(JPATH_ROOT . "/{$this->folder}") && !KunenaFolder::create(JPATH_ROOT . "/{$this->folder}")) {
         throw new RuntimeException(JText::_('Failed to create attachment directory.'));
     }
     $destination = JPATH_ROOT . "/{$this->folder}/{$this->filename}";
     // Move the file into the final location (if not already in there).
     if ($source != $destination) {
         // Create target directory if it does not exist.
         if (!$overwrite && is_file($destination)) {
             throw new RuntimeException(JText::sprintf('Attachment %s already exists.'), $this->filename_real);
         }
         if ($unlink) {
             @chmod($source, 0644);
         }
         $success = KunenaFile::copy($source, $destination);
         if (!$success) {
             throw new RuntimeException(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_NOT_MOVED', $destination));
         }
         KunenaPath::setPermissions($destination);
         if ($unlink) {
             unlink($source);
         }
     }
     return $this->save();
 }
開發者ID:densem-2013,項目名稱:exikom,代碼行數:61,代碼來源:attachment.php


注:本文中的KunenaAttachmentHelper::getAvailableFilename方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。