本文整理汇总了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;
}