2015-05-03 122 views
3

我在查找通过php上传文件到Microsoft OneDrive的代码示例。OneDrive通过php上传

我创建了一个微软帐户并创建了一个应用程序。

感谢配发

阿维

回答

4

尝试使用https://github.com/lovattj/php-skydrive

上传例如:

<?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; 
    } 
} 
+1

感谢分配 工作 –

0

参考:http://www.onlinecode.org/onedrive-file-upload-using-php/ 代码onedrive上传文件REST API

$real_uploadfile = $_FILES["uploadfile"]["name"];  
$temp = explode(".", $_FILES["uploadfile"]["name"]);  
$temp_ral = $temp[0]; 
$newfilename = date("Ymd").round(microtime(true)) .$temp_ral. '.' . end($temp).$file_name; 
$file_tmp = $_FILES['uploadfile']['tmp_name']; 
// check folder is exist in over system 
if (!file_exists('uploads')) { 
    // create new folder 
    mkdir('uploads', 0777, true); 
} 
$target_dir = "uploads/"; 
$uplode_path = $target_dir.$newfilename; 
move_uploaded_file($file_tmp,$uplode_path); 
$skydrive = new skydrive($token); 
// onedrive upload file using php 
$folderid = $_POST['folderid']; 

try { 
    $response_data = $skydrive->put_file($_GET['folderid'], $uplode_path); 
    // File was uploaded, return metadata. 
    print_r($response_data); 
} 
catch (Exception $exception) 
{ 
    // An error accrue for onedrive file upload using php 
    echo "Error: ".$exception->getMessage(); 
    exit; 
}