ALIOSS::upload_file_by_file PHP Метод

upload_file_by_file() публичный Метод

上传文件,适合比较大的文件
С версии: 2012-02-28
Автор: [email protected]
public upload_file_by_file ( string $bucket, string $object, string $file, array $options = null ) : ResponseCore
$bucket string (Required)
$object string (Required)
$file string (Required)
$options array (Optional)
Результат ResponseCore
    public function upload_file_by_file($bucket, $object, $file, $options = null)
    {
        //options
        $this->validate_options($options);
        if (!$options) {
            $options = array();
        }
        //bucket
        $this->is_empty($bucket, OSS_BUCKET_IS_NOT_ALLOWED_EMPTY);
        //object
        $this->is_empty($object, OSS_OBJECT_IS_NOT_ALLOWED_EMPTY);
        //file
        $this->is_empty($file, OSS_FILE_PATH_IS_NOT_ALLOWED_EMPTY);
        if ($this->chk_chinese($file)) {
            $file = iconv('utf-8', 'gbk', $file);
        }
        $options[self::OSS_FILE_UPLOAD] = $file;
        if (!file_exists($options[self::OSS_FILE_UPLOAD])) {
            throw new OSS_Exception($options[self::OSS_FILE_UPLOAD] . OSS_FILE_NOT_EXIST);
        }
        $filesize = filesize($options[self::OSS_FILE_UPLOAD]);
        $partsize = 1024 * 1024;
        //默认为 1M
        $extension = explode('.', $object);
        $ext = array_pop($extension);
        $content_type = MimeTypes::get_mimetype(strtolower($ext));
        $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
        $options[self::OSS_BUCKET] = $bucket;
        $options[self::OSS_OBJECT] = $object;
        $options[self::OSS_CONTENT_TYPE] = $content_type;
        $options[self::OSS_CONTENT_LENGTH] = $filesize;
        $response = $this->auth($options);
        return $response;
    }

Usage Example

Пример #1
0
 function upload($source, $target)
 {
     $obj = new ALIOSS();
     $obj->set_host_name($this->hostname, $this->port);
     $obj->set_debug_mode(FALSE);
     $bucket = $this->bucket;
     $response = $obj->upload_file_by_file($bucket, $target, $source);
     $rt = jishigou_oss::status($response);
     return $rt == '2' ? 1 : 0;
 }
All Usage Examples Of ALIOSS::upload_file_by_file