Перенаправление вывода консоли в файл

Проблема заключается в том, что для размещения файла с контентом вам нужно получить «content_path» каталога, в который вы хотите сохранить файл, а затем PUT новый файл под этим content_path. См. Приведенный ниже пример кода, который создает папку ~/Ubuntu One/phptestfolder, получает свой путь content_path и затем выдает файл foo.txt внутри этой вновь созданной папки.

<?php
# Set up OAuth with the token details you've previously saved
$conskey = 'CCCCCC';
$conssec = 'SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS';
$token = 'TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT';
$secret = 'ssssssssssssssssssssssssssssssssssssssssssssssssss';

$oauth = new OAuth($conskey,$conssec,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->enableSSLChecks();
$oauth->setToken($token,$secret);

# Create a folder in Ubuntu One.
# Folders are created by PUTting to the folder path with a PUT body of
# {"kind": "directory"} as explained at 
# https://one.ubuntu.com/developer/files/store_files/cloud/#put_apifile_storagev1pathtovolumepathtonode

$api_url = 'https://one.ubuntu.com/api/file_storage/v1/';
$oauth->fetch($api_url.'~/Ubuntu%20One/php-test-folder', '{"kind": "directory"}', OAUTH_HTTP_METHOD_PUT);
$response = json_decode($oauth->getLastResponse());
print_r($response);

# So now, we want to upload a file to that new folder. To do that, you need
# to get the directory content path. As explained at
# https://one.ubuntu.com/developer/files/store_files/cloud/#get_apifile_storagev1pathtovolumepathtonode
# "Note that a directory has a content_path. This means that you can PUT a new 
# file with content into that directory (see below) by PUTting to 
# CONTENT_ROOT + <directory.content-path> + '/' + filename.ext.
# CONTENT_ROOT is the root of the files API itself, /api/file_storage/v1/, but 
# temporarily it should be set to https://files.one.ubuntu.com. 
# (This note will be removed when this is fixed.)"
# So, we need the directory content path. This is returned in the output from
# the above statement ($oauth->getLastResponse). So, to put a file foo.txt
# with content "this is foo", the URL we need is:
# CONTENT_ROOT: https://files.one.ubuntu.com               +
# directory_content_path: $response['content_path']        +
# /: /                                                     +
# filename: foo.txt

# We want to urlencode the path (so that the space in "Ubuntu One", for example,
# becomes %20), but not any slashes therein (so the slashes don't become %2F).
# urlencode() encodes spaces as + so we need rawurlencode
$encpath = rawurlencode($response->content_path);
$encpath = str_replace("%2F", "/", $encpath);

$put_file_url = "https://files.one.ubuntu.com" . $encpath . "/" . "foo.txt";
$oauth->fetch($put_file_url, "this is foo", OAUTH_HTTP_METHOD_PUT, array('Content-Type'=>'application/json'));
$response = json_decode($oauth->getLastResponse());
print_r($response);

?>
0
задан 29 July 2017 в 16:46

0 ответов

Другие вопросы по тегам:

Похожие вопросы: