本文整理匯總了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();
}