<commit_before>#!/usr/bin/env php
<?php

require_once __DIR__.'/helper.php';
use \Dropbox as dbx;

list($client, $localPath, $dropboxPath) = parseArgs("upload-file", $argv, array(
        array("local-path", "The local path of the file to upload."),
        array("dropbox-path", "The path (on Dropbox) to save the file to."),
    ));

$pathError = dbx\Path::findErrorNonRoot($dropboxPath);
if ($pathError !== null) {
    fwrite(STDERR, "Invalid <dropbox-path>: $pathError\n");
    die;
}

$metadata = $client->uploadFile($dropboxPath, dbx\WriteMode::add(), fopen($localPath, "rb"), filesize($localPath));

print_r($metadata);<commit_msg>examples/upload-file: Allow data source to be a URL<commit_after>#!/usr/bin/env php
<?php

require_once __DIR__.'/helper.php';
use \Dropbox as dbx;

list($client, $sourcePath, $dropboxPath) = parseArgs("upload-file", $argv, array(
        array("source-path", "A path to a local file or a URL of a resource."),
        array("dropbox-path", "The path (on Dropbox) to save the file to."),
    ));

$pathError = dbx\Path::findErrorNonRoot($dropboxPath);
if ($pathError !== null) {
    fwrite(STDERR, "Invalid <dropbox-path>: $pathError\n");
    die;
}

$size = null;
if (\stream_is_local($sourcePath)) {
    $size = \filesize($sourcePath);
}

$metadata = $client->uploadFile($dropboxPath, dbx\WriteMode::add(), fopen($sourcePath, "rb"), $size);

print_r($metadata);
{'fraction_non_alphanumeric': 0.18344039971448964, 'fraction_numerical': 0.0, 'mean_word_length': 4.722448979591837, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2725530', 'n_tokens_mistral': 493, 'n_tokens_neox': 485, 'n_words': 118}