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


PHP Attachments::add方法代码示例

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


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

示例1: createGeneric


//.........这里部分代码省略.........
                 }
             }
         }
     }
     $attachments = new Attachments($this->_siteID);
     /* We can only check for duplicates right now if the file actually
      * exists. We'll do it again later below.
      */
     if ($fileExists && !$fileContents) {
         /* We store file size in KB, rounded to nearest KB. */
         $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;
         }
开发者ID:Hassanj343,项目名称:candidats,代码行数:67,代码来源:Attachments.php


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