Example #1
0
 function down()
 {
     $fileKey = $this->get('key');
     $storage = Alibaba::Storage();
     if (!$storage->fileExists($fileKey)) {
         throw new MHttpException(404);
     }
     $meta = $storage->getMeta($fileKey);
     if (!$meta['content-length']) {
         throw new MHttpException('file size is 0 or file not found');
     }
     $tmpFile = MONC . 'tmp' . DS . $fileKey;
     // 不存在,锁住下载
     if (!$storage->get($fileKey, $tmpFile)) {
         throw new Exception('fail to get file from[' . $fileKey . ']
             to [' . $tmpFile . ']');
     }
     header("Content-type: " . $meta['content-type']);
     header('Content-Disposition: attachment; filename="' . basename($fileKey) . '"');
     header("Content-Length: " . $meta['content-length']);
     echo readfile($tmpFile);
 }
Example #2
0
 public function __construct($sto)
 {
     $this->Storage = Alibaba::Storage($sto);
 }
Example #3
0
<?php

$storage = Alibaba::Storage();
file_put_contents("saveTextFile.jpg", 'test');
$res = $storage->saveFile("saveTextFile.jpg", "saveTextFile.jpg");
if (false == $res) {
    exit('saveFile failed.');
}
$res = $storage->saveText("saveTextFile.txt", "OK", -11);
if (false == $res) {
    exit('saveText failed.');
}
$res = $storage->fileExists("saveTextFile.txt");
if (false == $res) {
    exit('fileExists failed.');
}
$res = $storage->move("saveTextFile.txt", "newfile.txt");
if (false == $res) {
    exit('move failed.');
}
if ($storage->get("newfile.txt") != 'OK') {
    exit('get failed.');
}
print_r($storage->getMeta("newfile.txt"));
print_r($storage->copy("newfile.txt", "newfile2.txt"));
print_r($storage->listObject());
$res = $storage->delete("newfile.txt");
if (false == $res) {
    exit('delete failed.');
}
Example #4
0
/**
 * 删除远程服务器上的单个文件
 * 
 * @param $file
 * @return mixed
 */
function delete_remote_file($file)
{
    if (!false == strpos($file, '@!')) {
        return $file;
    }
    $oss_options = get_option('oss_options', TRUE);
    $config = array('id' => esc_attr($oss_options['ak']), 'key' => esc_attr($oss_options['sk']), 'bucket' => esc_attr($oss_options['bucket']), 'end_point' => esc_attr($oss_options['end_point']));
    $oss_upload_path = trim($oss_options['path'], '/');
    $wp_uploads = wp_upload_dir();
    $del_file = str_replace($wp_uploads['basedir'], '', $file);
    $del_file = ltrim($oss_upload_path . '/' . ltrim($del_file, '/'), '/');
    if (!is_object($aliyun_oss)) {
        $aliyun_oss = Alibaba::Storage($config);
    }
    $aliyun_oss->delete($del_file);
    return $file;
}
Example #5
0
 function ajax_get_sub()
 {
     global $_G;
     if (TAE) {
         $Storage = Alibaba::Storage();
         $res = $Storage->get("cates");
         if (!$res) {
             msg('未获取到分类,请先更新分类', 'error');
         }
         $sub_cate = json_decode($res, true);
         if (!$sub_cate || !is_array($sub_cate)) {
             msg('分类读取失败,请先更新分类', 'errot');
         }
     } else {
         $sub_cate = (include 'web/cache/cache_taobao_cate.php');
     }
     $cid = intval($_GET['cid']);
     if ($sub_cate[$cid]) {
         $string = '<select name="postdb[cid]"  class="select" ><option value="">------不限------</option>';
         foreach ($sub_cate[$cid]['sub'] as $k => $v) {
             $string .= "<option value='" . $v[cid] . "'>" . $v[name] . "</option>";
         }
         $string .= "</select>";
         $string = htmlspecialchars($string);
         json(array('status' => 'success', 'msg' => $string));
     } else {
         json(array('status' => 'error', 'msg' => '未找到子分类'));
     }
 }