Esempio n. 1
0
 public function getBookList($language, $ORDER, $BY, $LIMIT, $isFilter)
 {
     date_default_timezone_set('prc');
     require_once '../../../util/pcs/libs/BaiduPCS.class.php';
     require_once '../../../util/StackConst.php';
     require_once 'BookDao.php';
     $pcs = new BaiduPCS(StackConst::access_token());
     $path = StackConst::pcs_url() . "book/" . $language . "/";
     //根据time排序
     $by = $ORDER;
     //升序或降序
     $order = $BY;
     //记录区间
     $limit = $LIMIT;
     $result = $pcs->listFiles($path, $by, $order, $limit);
     $flist = json_decode($result);
     $arrBooks = array();
     $var = 0;
     $bookDao = new BookDao();
     for ($i = 0; $i < count($flist->list); $i++) {
         $bookNameBuf = substr(strrchr($flist->list[$i]->path, "/"), 1, strlen(strrchr($flist->list[$i]->path, "/")));
         //数据库不存在这个书返回true
         $isExit = $bookDao->isExitByBookName($bookNameBuf);
         if ($isFilter == 0 ? true : false || $isExit) {
             $arrBooks[$var++] = array('isExit' => $isExit, 'resource_book_language' => @$_POST['language'], 'resource_book_name' => $bookNameBuf, 'resource_book_url' => strrchr($flist->list[$i]->path, "book"), 'resource_book_size' => sprintf("%.2f", $flist->list[$i]->size / (1024 * 1024)), 'resource_book_level' => '', 'resource_book_review' => '', 'resource_book_word' => '', 'resource_book_date' => date('Y/m/d G:i:s', $flist->list[$i]->ctime));
         }
     }
     return $arrBooks;
 }
Esempio n. 2
0
 /**
  * 上传图片到PCS
  * @param 图片路径 $file
  * @param 图片名称【用户id+时间串】 $fileName 
  */
 public function upLoadPic($tmp_name, $fileName)
 {
     $rel = false;
     //引入pcs操作类
     require_once '../../../util/pcs/libs/BaiduPCS.class.php';
     require_once '../../../util/StackConst.php';
     //请根据实际情况更新$access_token与$appName参数
     $access_token = StackConst::access_token();
     //应用目录名"/apps/stack/shares/picture/"
     $targetPath = StackConst::pcs_pic_url();
     $pcs = new BaiduPCS($access_token);
     //新文件名默认给空
     $newFileName = "";
     $result = $pcs->upload(file_get_contents($tmp_name), $targetPath, $fileName, $newFileName);
     $flist = json_decode($result);
     if (isset($flist)) {
         $rel = $flist > 0 ? true : false;
     }
     //成功返回true/失败返回false
     return $rel;
 }
Esempio n. 3
0
File: diff.php Progetto: hsiun/doudo
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//默认值为'null'
$cursor = 'null';
$pcs = new BaiduPCS($access_token);
$result = $pcs->diff($cursor);
echo $result;
Esempio n. 4
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//源路径
$from = $root_dir . 'yun.jpg';
//目标路径
$to = $root_dir . 'yun11.jpg';
$pcs = new BaiduPCS($access_token);
$result = $pcs->moveSingle($from, $to);
echo $result;
Esempio n. 5
0
<?php

require_once 'BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//文件路径数组
$path = array($root_dir . 'yun.jpg', $root_dir . 'yun1.jpg');
$pcs = new BaiduPCS($access_token);
$result = $pcs->getBatchMeta($path);
echo $result;
Esempio n. 6
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//源路径
$from = $root_dir . 'yun.jpg';
//目标路径
$to = $root_dir . 'yun1.jpg';
$pcs = new BaiduPCS($access_token);
$result = $pcs->copySingle($from, $to);
echo $result;
Esempio n. 7
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//路径
$path = $root_dir . 'yun.jpg';
$pcs = new BaiduPCS($access_token);
$result = $pcs->downloadStream($path);
header('Content-Disposition:attachment;filename="yun.jpg"');
header('Content-Type:application/octet-stream');
echo $result;
Esempio n. 8
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//路径
$path = $root_dir . 'Lighthouse.jpg';
//待上传文件本地路径
$localPath = dirname(__FILE__) . '/' . 'Lighthouse.jpg';
//待秒传文件长度
$contentLength = filesize($localPath);
if ($contentLength < 256 * 1024) {
    exit('秒传文件必须大于256KB!');
}
//待秒传文件MD5
$contentMd5 = md5_file($localPath);
$handle = fopen($localPath, 'rb');
//待秒传文件校验段的MD5
$sliceMd5 = md5(fread($handle, 256 * 1024));
//文件crc32
$contentCrc32 = crc32($tmpFile);
$pcs = new BaiduPCS($access_token);
$result = $pcs->cloudMatch($path, $contentLength, $contentMd5, $sliceMd5, $contentCrc32);
fclose($handle);
echo $result;
Esempio n. 9
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//文件路径,此处列出的是应用根目录
$path = $root_dir;
//根据time排序
$by = 'time';
//升序或降序
$order = 'asc';
//记录区间
$limit = '0-9';
$pcs = new BaiduPCS($access_token);
$result = $pcs->listFiles($path, $by, $order, $limit);
echo $result;
Esempio n. 10
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//源路径数组
$from = array($root_dir . 'yun3.jpg', $root_dir . 'yun4.jpg');
//目标路径数组
$to = array($root_dir . 'yun5.jpg', $root_dir . 'yun6.jpg');
$pcs = new BaiduPCS($access_token);
$result = $pcs->moveBatch($from, $to);
echo $result;
Esempio n. 11
0
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//上传文件的目标保存路径,此处表示保存到应用根目录下
$targetPath = $root_dir;
//要上传的本地文件路径
//注意:此处使用本地文件来模拟客户端将文件进行分片,
//PHP本身是直接操作客户端文件的,需要借助Flash等具有客户端文件操作权限的插件来完成。
$file = dirname(__FILE__) . '/' . 'yun.jpg';
//文件名称
$fileName = basename($file);
//新文件名,为空表示使用原有文件名
$newFileName = '';
$pcs = new BaiduPCS($access_token);
if (!file_exists($file)) {
    exit('文件不存在,请检查路径是否正确');
} else {
    $fileSize = filesize($file);
    $handle = fopen($file, 'rb');
    //分片上传文件成功后返回的md5值数组集合
    $filesBlock = array();
    //设置分片上传文件块大小为20K
    $blockSize = 20480;
    if ($fileSize < $blockSize) {
        exit('请选择体积大于20480个字节的文件');
    }
    $isCreateSuperFile = TRUE;
    while (!feof($handle)) {
        $temp = $pcs->upload(fread($handle, $blockSize), $targetPath, $fileName, $newFileName, $isCreateSuperFile);
Esempio n. 12
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//图片路径
$path = $root_dir . 'yun.jpg';
//宽度
$width = 200;
//高度
$height = 200;
//质量
$quality = 10;
$pcs = new BaiduPCS($access_token);
$result = $pcs->thumbnail($path, $width, $height, $quality);
header('Content-type: image/jpeg');
echo $result;
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//离线下载数据在PCS中存放的路径
$savePath = $root_dir . '';
//要下载数据的URL
$sourceUrl = 'http://i5.hunantv.com/p1/20121221/0943375277.jpg';
//下载速度, byte/s
$rateLimit = 50;
//下载的超时时间
$timeout = 3600;
//回调URL,回调过程不处理302跳转
$callback = '';
$pcs = new BaiduPCS($access_token);
$result = $pcs->addOfflineDownloadTask($savePath, $sourceUrl, $rateLimit, $timeout, $callback);
echo $result;
Esempio n. 14
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//要创建的目录路径
$path = $root_dir . '.1.1.1.';
$pcs = new BaiduPCS($access_token);
$result = $pcs->makeDirectory($path);
echo $result;
Esempio n. 15
0
    exit;
}
// 利用上面拿到的path构建远程目录中的文件
$path = str_replace('//', '/', REMOTE_ROOT . '/' . $path);
$file_ext = strtolower(substr($path, strrpos($path, '.') + 1));
$file_name = substr($path, strrpos($path, '/') + 1);
// 缓存啦
header("Cache-Control: private, max-age=10800, pre-check=10800");
header("Pragma: private");
header("Expires: " . date(DATE_RFC822, strtotime(" 10 day")));
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
    header('Last-Modified: ' . $_SERVER['HTTP_IF_MODIFIED_SINCE'], true, 304);
    exit;
}
// 开始打印远程文件的内容
$BaiduPCS = new BaiduPCS(BAIDU_TOKEN);
if (in_array($file_ext, array('jpg', 'jpeg', 'png', 'gif', 'bmp'))) {
    $result = $BaiduPCS->downloadStream($path);
    $meta = json_decode($result, true);
    if (isset($meta['error_msg'])) {
        header("Content-Type: text/html; charset=utf8");
        echo $meta['error_msg'];
        exit;
    }
    header('Content-type: image/jpeg');
} elseif (in_array($file_ext, array('mp3', 'ogg', 'wma', 'wav', 'mp3pro', 'mid', 'midi'))) {
    $result = $BaiduPCS->downloadStream($path);
    $meta = json_decode($result, true);
    if (isset($meta['error_msg'])) {
        header("Content-Type: text/html; charset=utf8");
        echo $meta['error_msg'];
Esempio n. 16
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
$fileName = 'pic_list.jpg';
//文件路径
$path = $root_dir . $fileName;
$pcs = new BaiduPCS($access_token);
header('Content-Disposition:attachment;filename="' . $fileName . '"');
header('Content-Type:application/octet-stream');
$result = $pcs->download($path);
echo $result;
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//起始位置
$start = 0;
//返回多少个
$limit = 10;
//按开始时间升序 or 降序
$asc = 0;
//目标地址URL
$sourceURL = '';
//存放路径
$savePath = '';
//STARTTIMESTMAP, ENDTIMESTAMP, 如果不限制下限可写成"NULL, 1235", 不限制上线,可写成'1234,NULL'
$createTime = '';
//任务状态过滤
$status = 1;
//是否需要返回任务信息
$needTaskInfo = 1;
$pcs = new BaiduPCS($access_token);
$result = $pcs->listOfflineDownloadTask($start, $limit, $asc, $sourceURL, $savePath, $createTime, $status, $needTaskInfo);
echo $result;
Esempio n. 18
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//文件路径数组
$path = array($root_dir . 'yun3.jpg', $root_dir . 'yun4.jpg');
$pcs = new BaiduPCS($access_token);
$result = $pcs->deleteBatch($path);
echo $result;
Esempio n. 19
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//上传文件的目标保存路径,此处表示保存到应用根目录下
$targetPath = $root_dir;
//要上传的本地文件路径
$file = dirname(__FILE__) . '/' . 'yun.jpg';
//文件名称
$fileName = basename($file);
//新文件名,为空表示使用原有文件名
$newFileName = '';
$pcs = new BaiduPCS($access_token);
if (!file_exists($file)) {
    exit('文件不存在,请检查路径是否正确');
} else {
    $fileSize = filesize($file);
    $handle = fopen($file, 'rb');
    $fileContent = fread($handle, $fileSize);
    $result = $pcs->upload($fileContent, $targetPath, $fileName, $newFileName);
    fclose($handle);
    echo $result;
}
Esempio n. 20
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//文件路径
$path = $root_dir . '';
$pcs = new BaiduPCS($access_token);
$result = $pcs->getMeta($path);
echo $result;
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//要查询的task_id列表,如:'1,2,3,4'
$taskIds = 2463;
//0:查任务信息,1:查进度信息
$opType = 1;
$pcs = new BaiduPCS($access_token);
$result = $pcs->queryOfflineDownloadTask($taskIds, $opType);
echo $result;
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//离线下载任务Id
$taskId = 2462;
$pcs = new BaiduPCS($access_token);
$result = $pcs->cancelOfflineDownloadTask($taskId);
echo $result;
Esempio n. 23
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//文件路径
$path = $root_dir . 'yun3.jpg';
$pcs = new BaiduPCS($access_token);
$result = $pcs->deleteSingle($path);
echo $result;
Esempio n. 24
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
$pcs = new BaiduPCS($access_token);
echo $pcs->getQuota();
Esempio n. 25
0
File: apps.php Progetto: hsiun/doudo
<?php

require_once '../libs/BaiduPCS.class.php';
require_once 'config.php';
$root_dir = '/apps' . '/';
$path = $root_dir . '.1.1.1.1.';
$pcs = new BaiduPCS($access_token);
#echo $pcs->getQuota();
echo $pcs->makeDirectory($path);
Esempio n. 26
0
function upload_baidupcs($zip_file_path)
{
    $file_blocks = array();
    //分片上传文件成功后返回的md5值数组集合
    $file_block_size = 2 * 1024 * 1024;
    // 2M
    $rmote_dir = str_replace('//', '/', REMOTE_ROOT . '/backup/');
    $file_name = basename($zip_file_path);
    $BaiduPCS = new BaiduPCS(BAIDU_TOKEN);
    // 开始分片上传
    $handle = @fopen($zip_file_path, 'rb');
    while (!@feof($handle)) {
        $file_block_content = fread($handle, $file_block_size);
        $temp = $BaiduPCS->upload($file_block_content, $remote_dir, $file_name, false, true);
        if (!is_array($temp)) {
            $temp = json_decode($temp, true);
        }
        if (isset($temp['md5'])) {
            array_push($file_blocks, $temp['md5']);
        }
    }
    fclose($handle);
    //@unlink($zip_file_path);
    if (count($file_blocks) > 1) {
        $BaiduPCS->createSuperFile($remote_dir, $file_name, $file_blocks, '');
    }
}
Esempio n. 27
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//路径
$path = $root_dir . '两只老虎.MP4';
$pcs = new BaiduPCS($access_token);
$result = $pcs->streaming($path);
echo $result;
Esempio n. 28
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//取值为video,audio,image,doc四种
$type = 'image';
//返回条目控制起始值n1,缺省为0
$start = 0;
//返回条目控制长度n2,缺省为1000,可配置
$limit = 1000;
//需要过滤的前缀路径,如/apps/album
$filter_path = '';
$pcs = new BaiduPCS($access_token);
$result = $pcs->listStream($type, $start, $limit, $filter_path);
echo $result;
Esempio n. 29
0
<?php

require_once '../libs/BaiduPCS.class.php';
//请根据实际情况更新$access_token与$appName参数
$access_token = '3.839af46f54db6ed60797847d2febbca0.2592000.1359262544.754976761-248414';
//应用目录名
$appName = '测试应用';
//应用根目录
$root_dir = '/apps' . '/' . $appName . '/';
//搜索关键字
$wd = 'jpg';
//搜索的目录路径,此处为搜索应用根目录
$path = $root_dir;
//是否递归搜索
$re = 1;
$pcs = new BaiduPCS($access_token);
$result = $pcs->search($path, $wd, $re);
echo $result;