create onedrive folder using php – how to create folder in onedrive

create onedrive folder using php – how to create folder in onedrive

in this post we will show you create onedrive folder using php. For create onedrive folder you need register you app and get CLIENT-ID, CLIENT-SECRET and CALLBACK-URL.

For add CLIENT-ID, CLIENT-SECRET and CALLBACK-URL go to src/functions.inc.php. Pass CALLBACK-URL as example/callback.php

Create a new folder in OneDrive using php

we have to Create a new folder in a specified parent item or parent path using php .

Prerequisites for Create a new folder in OneDrive using php

Create a new folder in OneDrive using php, the user must have granted/need the app write access to the parent folder of the new item.

HTTP request for onedrive folder using php

POST /drive/items/{parent-id}/children

Example for onedrive folder using php

Here is an example of how to create a new folder in OneDrive using php.

POST /drive/root/children
Content-Type: applicationhttps://www.onlinecode.org/json

{
"name": "onlinecode",
"folder": { }
}

This is complete package for onedrive rest api using php ::

Download

<?php

// code for onedrive folder using php
// go to downlode package and include header.inc.php 
require_once "header.inc.php";
// go to downlode package and in "src" folder and  include functions.inc.php 
require_once "../src/functions.inc.php";

// we Call this function to grab 
// a current false or access_token if none this is available.
$get_token = skydrive_tokenstore::acquire_token();


if (!$get_token) { 
	// token not found 
	// If not found token at that time prompt to login. 
	// and Call skydrive_auth::build_oauth_url() to get the redirect URL and login procsee.
	echo "
"; echo " "; echo "Login with SkyDrive"; echo "
"; } else { // get floder name suing post if (empty($_POST['foldername'])) { echo 'Error - no new folder name specified'; } else { $obj_skydrive = new skydrive($get_token); try { // get current folder id if (empty($_POST['currentfolderid'])) { $currentfolderid_response = $obj_skydrive->create_folder(null, $_POST['foldername'], 'Description'); } else { $currentfolderid_response = $obj_skydrive->create_folder($_POST['currentfolderid'], $_POST['foldername'], 'Description'); } // return metadata and Folder was created. print_r($currentfolderid_response); } catch (Exception $exception) { // An error occured, create onedrive folder using php echo "Error for create folder : ".$exception->getMessage(); exit; } } } require_once "footer.inc.php";

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  13  =  14

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US