利用PHP把图片上传播七牛

电动加载类

<?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>

PHP,  

相关文章