本文整理匯總了PHP中Storage::unlink方法的典型用法代碼示例。如果您正苦於以下問題:PHP Storage::unlink方法的具體用法?PHP Storage::unlink怎麽用?PHP Storage::unlink使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Storage
的用法示例。
在下文中一共展示了Storage::unlink方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: start
/**
* 應用程序初始化
* @access public
* @return void
*/
public static function start()
{
// 設定錯誤和異常處理
register_shutdown_function('Think\\Think::fatalError');
set_error_handler('Think\\Think::appError');
set_exception_handler('Think\\Think::appException');
// 注冊AUTOLOAD方法
spl_autoload_register('Think\\Think::autoload');
// 初始化文件存儲方式
Storage::connect(STORAGE_TYPE);
$runtimefile = RUNTIME_PATH . APP_MODE . '~runtime.php';
if (!APP_DEBUG && Storage::has($runtimefile, 'runtime')) {
Storage::load($runtimefile, null, 'runtime');
} else {
if (Storage::has($runtimefile, 'runtime')) {
Storage::unlink($runtimefile, 'runtime');
}
$content = '';
// 讀取應用模式
$mode = (include is_file(COMMON_PATH . 'Conf/core.php') ? COMMON_PATH . 'Conf/core.php' : THINK_PATH . 'Conf/Mode/' . APP_MODE . '.php');
// 加載核心文件
foreach ($mode['core'] as $file) {
if (is_file($file)) {
include $file;
if (!APP_DEBUG) {
$content .= compile($file);
}
}
}
// 加載配置文件
foreach ($mode['config'] as $key => $file) {
is_numeric($key) ? C(include $file) : C($key, include $file);
}
// 加載別名定義
foreach ($mode['alias'] as $alias) {
self::addMap(is_array($alias) ? $alias : (file_exists($alias) ? include $alias : array()));
}
// 加載模式係統行為定義
if (isset($mode['extends'])) {
Hook::import(is_array($mode['extends']) ? $mode['extends'] : (include $mode['extends']));
}
// 加載應用行為定義
if (isset($mode['tags'])) {
if (is_array($mode['tags'])) {
$tags = $mode['tags'];
} else {
$tags = file_exists($mode['tags']) ? include $mode['tags'] : array();
}
Hook::import($tags);
}
// 加載框架底層語言包
L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php');
if (!APP_DEBUG) {
$content .= "\nnamespace { Think\\Think::addMap(" . var_export(self::$_map, true) . ");";
$content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(Hook::get(), true) . ');}';
Storage::put($runtimefile, strip_whitespace('<?php ' . $content), 'runtime');
} else {
// 調試模式加載係統默認的配置文件
C(include THINK_PATH . 'Conf/debug.php');
// 讀取調試模式的應用狀態
$status = C('APP_STATUS');
// 加載對應的項目配置文件
if (is_file(COMMON_PATH . 'Conf/' . $status . '.php')) {
// 允許項目增加開發模式配置定義
C(include COMMON_PATH . 'Conf/' . $status . '.php');
}
}
}
// 設置係統時區
date_default_timezone_set(C('DEFAULT_TIMEZONE'));
// 檢查項目目錄結構 如果不存在則自動創建
if (C('CHECK_APP_DIR') && !is_dir(LOG_PATH)) {
// 創建項目目錄結構
require THINK_PATH . 'Common/build.php';
}
// 記錄加載文件時間
G('loadTime');
if (!defined('IsInterface')) {
// 運行應用
App::run();
} else {
App::init();
}
}
示例2: start
/**
* 應用程序初始化
* @access public
* @return void
*/
public static function start()
{
// 注冊AUTOLOAD方法
spl_autoload_register('Think\\Think::autoload');
// 設定錯誤和異常處理
register_shutdown_function('Think\\Think::fatalError');
set_error_handler('Think\\Think::appError');
set_exception_handler('Think\\Think::appException');
// 初始化文件存儲方式
Storage::connect(STORAGE_TYPE);
$runtimefile = RUNTIME_PATH . APP_MODE . '~runtime.php';
if (!APP_DEBUG && Storage::has($runtimefile)) {
Storage::load($runtimefile);
} else {
if (Storage::has($runtimefile)) {
Storage::unlink($runtimefile);
}
$content = '';
// 讀取應用模式
$mode = (include is_file(CONF_PATH . 'core.php') ? CONF_PATH . 'core.php' : MODE_PATH . APP_MODE . '.php');
// 加載核心文件
foreach ($mode['core'] as $file) {
if (is_file($file)) {
include $file;
if (!APP_DEBUG) {
$content .= compile($file);
}
}
}
// 加載應用模式配置文件
foreach ($mode['config'] as $key => $file) {
is_numeric($key) ? C(include $file) : C($key, include $file);
}
// 讀取當前應用模式對應的配置文件
if ('common' != APP_MODE && is_file(CONF_PATH . 'config_' . APP_MODE . '.php')) {
C(include CONF_PATH . 'config_' . APP_MODE . '.php');
}
// 加載模式別名定義
if (isset($mode['alias'])) {
self::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias']));
}
// 加載應用別名定義文件
if (is_file(CONF_PATH . 'alias.php')) {
self::addMap(include CONF_PATH . 'alias.php');
}
// 加載模式行為定義
if (isset($mode['tags'])) {
Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags']));
}
// 加載應用行為定義
if (is_file(CONF_PATH . 'tags.php')) {
// 允許應用增加開發模式配置定義
Hook::import(include CONF_PATH . 'tags.php');
}
// 加載框架底層語言包
L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php');
if (!APP_DEBUG) {
$content .= "\nnamespace { Think\\Think::addMap(" . var_export(self::$_map, true) . ");";
$content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(Hook::get(), true) . ');}';
Storage::put($runtimefile, strip_whitespace('<?php ' . $content));
} else {
// 調試模式加載係統默認的配置文件
C(include THINK_PATH . 'Conf/debug.php');
// 讀取應用調試配置文件
if (is_file(CONF_PATH . 'debug.php')) {
C(include CONF_PATH . 'debug.php');
}
}
}
// 讀取當前應用狀態對應的配置文件
if (APP_STATUS && is_file(CONF_PATH . APP_STATUS . '.php')) {
C(include CONF_PATH . APP_STATUS . '.php');
}
// 設置係統時區
date_default_timezone_set(C('DEFAULT_TIMEZONE'));
// 檢查應用目錄結構 如果不存在則自動創建
if (C('CHECK_APP_DIR') && !is_dir(LOG_PATH)) {
// 創建應用目錄結構
require THINK_PATH . 'Common/build.php';
}
// 記錄加載文件時間
G('loadTime');
// 運行應用
App::run();
}
示例3: testStorage
function testStorage()
{
// test Storage - public API
// store test.txt
echo "saving test.txt with a crazy name\n";
$file_id = Storage::save('test.txt', 'O*Bc3wukygfsT@#($0876)$!@#*+_][.txt');
echo "resulting file_id = {$file_id}\n";
$file = Dal::query_one_object("SELECT * FROM files WHERE file_id=?", array($file_id));
$this->assertEquals($file->link_count, 0);
$this->assertEquals($file->last_linked, NULL);
$file_path = Storage::getPath($file_id);
$file_url = Storage::getURL($file_id);
echo "getPath({$file_id}) -> {$file_path}\n";
echo "getURL({$file_id}) -> {$file_url}\n";
$this->assertTrue(strpos($file_path, PA::$path . "/web/files/") === 0);
$this->assertTrue(strpos($file_url, PA::$url) === 0);
// link it in somewhere
$link_id = Storage::link($file_id, array('role' => 'avatar', 'user' => 1));
echo "linked it in as avatar for user 1; link_id = {$link_id}\n";
$link = Dal::query_one_object("SELECT * FROM file_links WHERE link_id=?", array($link_id));
$this->assertEquals($link->file_id, $file_id);
$file = Dal::query_one_object("SELECT * FROM files WHERE file_id=?", array($file_id));
$this->assertEquals($file->link_count, 1);
$this->assertNotEquals($file->last_linked, NULL);
// another file
$child_file_id = Storage::save('test2.txt', 'this is the child file.jpg', 'throwaway', 'image/jpeg');
echo "child file: {$child_file_id}\n";
$child_file = Dal::query_one_object("SELECT * FROM files WHERE file_id=?", array($child_file_id));
$child_file_path = Storage::getPath($child_file_id);
$child_file_url = Storage::getURL($child_file_id);
echo "getPath({$child_file_id}) -> {$child_file_path}\n";
echo "getURL({$child_file_id}) -> {$child_file_url}\n";
$this->assertTrue(strpos($child_file_path, PA::$path . "/web/files/") === 0);
$this->assertTrue(strpos($child_file_url, PA::$url) === 0);
// link child file in as a thumbnail of first file
$child_link_id = Storage::link($child_file_id, array('role' => 'thumb', 'file' => $file_id, 'dim' => '123x123'));
echo "child link id: {$child_link_id}\n";
$child_link = Dal::query_one_object("SELECT * FROM file_links WHERE link_id=?", array($child_link_id));
$this->assertEquals($child_link->file_id, $child_file_id);
$this->assertEquals($child_link->parent_file_id, $file_id);
$child_file = Dal::query_one_object("SELECT * FROM files WHERE file_id=?", array($child_file_id));
$this->assertEquals($child_file->link_count, 1);
$this->assertNotEquals($child_file->last_linked, NULL);
// this should fail (missing role)
try {
Storage::link($file_id, array("user" => 1));
$this->fail("Expected exception");
} catch (PAException $e) {
$this->assertEquals($e->getCode(), BAD_PARAMETER);
}
// this should fail (missing network)
try {
Storage::link($file_id, array("role" => "header", "group" => 42));
$this->fail("Expected exception");
} catch (PAException $e) {
$this->assertEquals($e->getCode(), BAD_PARAMETER);
}
// this should fail (network not valid)
try {
Storage::link($file_id, array("role" => "thumb", "network" => 1, "file" => $file_id, "dim" => "123x123"));
$this->fail("Expected exception");
} catch (PAException $e) {
$this->assertEquals($e->getCode(), BAD_PARAMETER);
}
// this should fail (parent_file_id == file_id)
try {
$link_id = Storage::link($file_id, array("role" => "thumb", "file" => $file_id, "dim" => "123x123"));
$this->fail("Expected exception");
} catch (PAException $e) {
$this->assertEquals($e->getCode(), BAD_PARAMETER);
}
// Now unlink the two files we just created ...
// unlink the first - but don't delete it
Storage::unlink($file_id, $link_id, FALSE);
// make sure it's gone
$this->assertEquals(Dal::query_one("SELECT * FROM file_links WHERE link_id=?", array($link_id)), NULL);
// the file should still be there, with zero links, though
$file = Dal::query_one("SELECT * FROM files WHERE file_id=?", array($file_id));
$this->assertNotEquals($file, NULL);
$this->assertEquals($file->link_count, 0);
// try a bad unlink operation
try {
Storage::unlink($file_id, $child_link_id);
$this->fail("Expected exception");
} catch (PAException $e) {
$this->assertEquals($e->getCode(), FILE_NOT_FOUND);
}
// unlink and delete the second
Storage::unlink($child_file_id, $child_link_id);
// make sure it's gone
$this->assertEquals(Dal::query_one("SELECT * FROM file_links WHERE link_id=?", array($child_link_id)), NULL);
// and make sure the file is gone too
$this->assertEquals(Dal::query_one("SELECT * FROM files WHERE file_id=?", array($child_file)), NULL);
// reap unlinked files (immediately - no grace period)
Storage::cleanupFiles(-1, -1);
// make sure the first file is now gone
$this->assertEquals(Dal::query_one("SELECT * FROM files WHERE file_id=?", array($file_id)), NULL);
}