本文整理汇总了PHP中Documents::FindByFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP Documents::FindByFilename方法的具体用法?PHP Documents::FindByFilename怎么用?PHP Documents::FindByFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Documents
的用法示例。
在下文中一共展示了Documents::FindByFilename方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize_page
function initialize_page()
{
$post_action = "";
if (isset($_POST['submit'])) {
$post_action = $_POST['submit'];
}
if ($post_action == "Add Document" || $post_action == "Add and Return to List") {
$name = $_POST['name'];
$file_type = getFileExtension($_FILES['file']['name']);
$filename = slug(getFileName($_FILES['file']['name']));
$filename_string = $filename . "." . $file_type;
// Check to make sure there isn't already a file with that name
$possibledoc = Documents::FindByFilename($filename_string);
if (is_object($possibledoc)) {
setFlash("<h3>Failure: Document filename already exists!</h3>");
redirect("admin/add_document");
}
$target_path = SERVER_DOCUMENTS_ROOT . $filename_string;
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
$new_doc = MyActiveRecord::Create('Documents', array('name' => $name, 'filename' => $filename_string, 'file_type' => $file_type));
$new_doc->save();
if (!chmod($target_path, 0644)) {
setFlash("<h3>Warning: Document Permissions not set; this file may not display properly</h3>");
}
setFlash("<h3>Document uploaded</h3>");
} else {
setFlash("<h3>Failure: Document could not be uploaded</h3>");
}
if ($post_action == "Add and Return to List") {
redirect("admin/list_documents");
}
}
}
示例2: document_display
function document_display($content_to_display)
{
$documentPattern = "/{{2}(document:[A-Za-z0-9\\-\\_ \\.\\(\\)'\"]+){{2}/";
$documentIds = getFilterIds($content_to_display, $documentPattern);
$documents = array();
foreach ($documentIds as $documentId) {
$filename = end(explode(":", $documentId));
$documents[] = Documents::FindByFilename($filename);
}
foreach ($documents as $document) {
if (is_object($document)) {
$replacement = "<a class=\"hcd-document " . getFileExtension($document->filename) . "\" href=\"{$document->getPublicUrl()}\">" . cleanupSpecialChars($document->name) . "</a> (" . getFileExtension($document->filename) . ")";
$content_to_display = updateContent($content_to_display, "/{{2}document:" . str_replace(")", "\\)", str_replace("(", "\\(", $document->filename)) . "{{2}/", $replacement);
} else {
$content_to_display = "<span class=\"database_error\">HCd>CMS Warning: Document “{$filename}” not found!</span> " . $content_to_display;
}
}
return $content_to_display;
}