OneDrive upload via php

19,084

Try use https://github.com/lovattj/php-skydrive

Upload example:

<?php
require_once 'functions.inc.php';
$token = skydrive_tokenstore::acquire_token(); // Call this function to grab a current access_token, or false if none is available.

if (!$token) { // If no token, prompt to login. Call skydrive_auth::build_oauth_url() to get the redirect URL.
    echo "<div>";
    echo "<img src='statics/key-icon.png'>&nbsp";
    echo "<a href='" . skydrive_auth::build_oauth_url() . "'>Login with SkyDrive</a></span>";
    echo "</div>";
} else {
    $sd = new skydrive($token);
    try {
        $response = $sd->put_file($_GET['folderid'], '/file/to/put');
        // File was uploaded, return metadata.
        print_r($response);
    } catch (Exception $e) {
        // An error occured, print HTTP status code and description.
        echo "Error: ".$e->getMessage();
        exit;
    }
}
Share:
19,084
אVי
Author by

אVי

Updated on August 21, 2022

Comments

  • אVי
    אVי over 1 year

    I'm looking for a code example for uploading a file to Microsoft OneDrive via php.

    I have created a microsoft account and created an app.

    Thanks allot

    Avi