mvp
This commit is contained in:
commit
465f0fef51
79
index.php
Normal file
79
index.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
$share_url = "https://1drv.ms/f/s!AhzmQMxm1n467DZsz0ev8jKEqskE";
|
||||
$path = $_GET['path'];
|
||||
|
||||
function get_encodedURL($share_url) {
|
||||
$base64Value = base64_encode($share_url);
|
||||
return "https://api.onedrive.com/v1.0/shares/u!" . str_replace("+","-",str_replace("/","_",rtrim($base64Value,"=")));
|
||||
}
|
||||
|
||||
function get_folder_object_url($share_url) {
|
||||
return get_encodedURL($share_url) . "/driveItem?\$expand=children";
|
||||
}
|
||||
|
||||
function get_folder_object($share_url) {
|
||||
$folder_object_url = get_folder_object_url($share_url);
|
||||
$response = file_get_contents($folder_object_url);
|
||||
return json_decode($response, true);
|
||||
}
|
||||
|
||||
function get_item_from_path($folder_share_url, $path) {
|
||||
$result = Array();
|
||||
$res = get_folder_object($folder_share_url);
|
||||
if ($path == "/" || $path == "") {
|
||||
$result['pathvalid'] = true;
|
||||
$result['isfolder'] = true;
|
||||
$result['data'] = $res;
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (isset($res['children']) && count($res['children']) > 0) {
|
||||
$items = $res['children'];
|
||||
$nodes = explode('/',substr($path, 1), 2);
|
||||
$next = $nodes[0];
|
||||
$rest = count($nodes) > 1 ? $nodes[1] : "";
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item['name'] == $next) {
|
||||
if (isset($item['folder'])) {
|
||||
return get_item_from_path($item['webUrl'], "/" . $rest);
|
||||
} else if (isset($item['file'])) {
|
||||
$result['pathvalid'] = true;
|
||||
$result['isfolder'] = false;
|
||||
$result['data'] = $item;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$result['pathvalid'] = false;
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
$result = get_item_from_path($share_url, $path);
|
||||
|
||||
if ($result['pathvalid'] && $result['isfolder'] == false) {
|
||||
$download_url = $result['data']['@content.downloadUrl'];
|
||||
header("Location: $download_url", true, 302);
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Download</title>
|
||||
</head>
|
||||
|
||||
<body id="index-page">
|
||||
<?php
|
||||
// echo count(get_folder_object($share_url)['children']);
|
||||
echo ($result['pathvalid'] ? ($result['isfolder'] ? "path is folder" : ("the download link to file is: " . $result['data']['@content.downloadUrl'])) : "path not valid");
|
||||
// echo "<b>" . substr($path, 1) . "</b> does not exists!";
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user