自動載入類 上傳代碼: ...
自動載入類
<?php function classLoader($class) { $path = str_replace('\\', DIRECTORY_SEPARATOR, $class); $file = __DIR__ . '/src/' . $path . '.php'; if (file_exists($file)) { require_once $file; } } spl_autoload_register('classLoader'); require_once __DIR__ . '/Qiniu/functions.php';
上傳代碼:
<?php /**
* 七牛上傳 *
* $accessKey 申請時七牛會提供
* $secretKey 申請時七牛會提供
*
*/
require_once __DIR__ .'./Qiniu/Config.php'; require_once __DIR__ .'./Qiniu/Auth.php'; require_once __DIR__ .'./Qiniu/Storage/UploadManager.php'; require_once __DIR__ .'./Qiniu/Zone.php'; require_once './autoload.php'; use Qiniu\Auth; use Qiniu\Storage\UploadManager; $accessKey = 'xxxxxxxx'; $secretKey = 'xxxxxxxxxxxx'; $auth = new Auth($accessKey ,$secretKey);//制定秘鑰 $uploadMgr = new UploadManager(); $bucket = "unlock";//空間 $policy= array( "saveKey"=>"$(year)$(mon)$(day)$(hour)$(min)$(sec)/$(etag)" ); $token = $auth->uploadToken($bucket, null, 3600*3600,$policy); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form method="post" action="http://up.qiniu.com" enctype="multipart/form-data"> <input name="token" type="hidden" value="<?php echo $token;?>"> <input name="file" type="file" /> <input type="submit" value="上傳"/> </form> </body> </html>