本文整理汇总了PHP中ArticleFileManager::truncateFileName方法的典型用法代码示例。如果您正苦于以下问题:PHP ArticleFileManager::truncateFileName方法的具体用法?PHP ArticleFileManager::truncateFileName怎么用?PHP ArticleFileManager::truncateFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArticleFileManager
的用法示例。
在下文中一共展示了ArticleFileManager::truncateFileName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleCopy
/**
* PRIVATE routine to copy an article file and add it to the database.
* @param $url original filename/url of the file
* @param $mimeType string the mime type of the file
* @param $fileStage string identifying type
* @param $fileId int ID of an existing file to update
* @param $overwrite boolean overwrite all previous revisions of the file (revision number is still incremented)
* @return int the file ID (false if upload failed)
*/
function handleCopy($url, $mimeType, $fileStage, $fileId = null, $overwrite = false)
{
if (HookRegistry::call('ArticleFileManager::handleCopy', array(&$url, &$mimeType, &$fileStage, &$fileId, &$overwrite, &$result))) {
return $result;
}
$articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
$fileStagePath = $this->fileStageToPath($fileStage);
$dir = $this->filesDir . $fileStagePath . '/';
if (!$fileId) {
// Insert dummy file to generate file id FIXME?
$dummyFile = true;
$articleFile =& $this->generateDummyFile($this->article);
} else {
$dummyFile = false;
$articleFile = new ArticleFile();
$articleFile->setRevision($articleFileDao->getRevisionNumber($fileId) + 1);
$articleFile->setArticleId($this->articleId);
$articleFile->setFileId($fileId);
$articleFile->setDateUploaded(Core::getCurrentDate());
$articleFile->setDateModified(Core::getCurrentDate());
}
$articleFile->setFileType($mimeType);
$articleFile->setOriginalFileName(ArticleFileManager::truncateFileName(basename($url), 127));
$articleFile->setFileStage($fileStage);
$articleFile->setRound($this->article->getCurrentRound());
$newFileName = $this->generateFilename($articleFile, $fileStage, $articleFile->getOriginalFileName());
if (!$this->copyFile($url, $dir . $newFileName)) {
// Delete the dummy file we inserted
$articleFileDao->deleteArticleFileById($articleFile->getFileId());
return false;
}
$articleFile->setFileSize(filesize($dir . $newFileName));
if ($dummyFile) {
$articleFileDao->updateArticleFile($articleFile);
} else {
$articleFileDao->insertArticleFile($articleFile);
}
if ($overwrite) {
$this->removePriorRevisions($articleFile->getFileId(), $articleFile->getRevision());
}
return $articleFile->getFileId();
}