当前位置: 首页>>代码示例>>PHP>>正文


PHP Attachments::setDirectoryName方法代码示例

本文整理汇总了PHP中Attachments::setDirectoryName方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachments::setDirectoryName方法的具体用法?PHP Attachments::setDirectoryName怎么用?PHP Attachments::setDirectoryName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Attachments的用法示例。


在下文中一共展示了Attachments::setDirectoryName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createGeneric


//.........这里部分代码省略.........
         $fileSize = round(@filesize($tempFilename) / 1024);
         /* The md5sum is stored for duplicate checking. */
         $md5sum = @md5_file($tempFilename);
         /* Check for duplicates. */
         $duplicates = $attachments->getMatching($dataItemType, $dataItemID, $fileSize, $md5sum, $extractedText);
         /* Duplicate attachments are never added, but this is not a fatal
          * error. We will set a property to notify the caller that a
          * duplicate occurred.
          */
         if (!empty($duplicates)) {
             $this->_duplicatesOccurred = true;
             if (file_exists($tempFilename)) {
                 unlink($tempFilename);
             }
             return false;
         }
     } else {
         $fileSize = 0;
         $md5sum = '';
     }
     /* Add the attachment record. At this point, there is no actual
      * associated directory / full file path.
      */
     $attachmentID = $attachments->add($dataItemType, $dataItemID, $attachmentTitle, $originalFilename, $storedFilename, $contentType, $extractText, $extractedText, $isProfileImage, '', $fileSize, $md5sum);
     /* Were we successful? */
     if (!$attachmentID) {
         $this->_isError = true;
         $this->_error = 'Error adding attachment to the database.';
         @unlink($tempFilename);
         return false;
     }
     /* Store the extracted text and attachment ID in properties for later
      * access.
      */
     $this->_extractedText = $extractedText;
     $this->_attachmentID = $attachmentID;
     /* Create the attachment directory. */
     $uniqueDirectory = $this->_createDirectory($attachmentID, $storedFilename);
     if (!$uniqueDirectory) {
         $attachments->delete($attachmentID, false);
         return false;
     }
     /* Create the full path name to the file. */
     $newFileFullPath = $uniqueDirectory . $storedFilename;
     /* Are we creating a new file from file contents, or are we moving a
      * temporary file?
      */
     if ($fileContents !== false) {
         $status = @file_put_contents($newFileFullPath, $fileContents);
         if (!$status) {
             $this->_isError = true;
             $this->_error = sprintf('Cannot create file %s.', $newFileFullPath);
             $attachments->delete($attachmentID, false);
             @unlink($uniqueDirectory);
             return false;
         }
         /* We store file size in KB, rounded to nearest KB. */
         $fileSize = round(@filesize($newFileFullPath) / 1024);
         /* The md5sum is stored for duplicate checking. */
         $md5sum = @md5_file($newFileFullPath);
         /* Check for duplicates. */
         $duplicates = $attachments->getMatching($dataItemType, $dataItemID, $fileSize, $md5sum, $extractedText);
         /* Duplicate attachments are never added, but this is not a fatal
          * error. We will set a property to notify the caller that a
          * duplicate occurred.
          */
         if (!empty($duplicates)) {
             $this->_duplicatesOccurred = true;
             $attachments->delete($attachmentID, false);
             @unlink($newFileFullPath);
             @unlink($uniqueDirectory);
             return false;
         }
     } else {
         if ($fileExists) {
             /* Copy the temp file to the new path. */
             if (!@copy($tempFilename, $newFileFullPath)) {
                 $this->_isError = true;
                 $this->_error = sprintf('Cannot copy temporary file %s to %s.', $tempFilename, $newFileFullPath);
                 $attachments->delete($attachmentID, false);
                 @unlink($newFileFullPath);
                 @unlink($uniqueDirectory);
                 return false;
             }
             /* Try to remove the temp file; if it fails it doesn't matter. */
             @unlink($tempFilename);
         }
     }
     /* Store path to the file (inside the attachments directory) in this
      * object.
      */
     $this->_newFilePath = $newFileFullPath;
     $this->_containingDirectory = $uniqueDirectory;
     /* Update the database with the new directory name. */
     $attachments->setDirectoryName($attachmentID, str_replace('./attachments/', '', $uniqueDirectory));
     if (!eval(Hooks::get('CREATE_ATTACHMENT_FINISHED'))) {
         return;
     }
     return true;
 }
开发者ID:Hassanj343,项目名称:candidats,代码行数:101,代码来源:Attachments.php


注:本文中的Attachments::setDirectoryName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。