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