当任何用户从Google云端硬盘选择器中选择文件时,我想将文件从Google云端硬盘直接传输到我的服务器。我正在使用以下代码,但在使用以下代码时,文件无法下载到我的特定文件夹中。
回调功能:
function downloadFile(item) {
var request = new XMLHttpRequest();
var mimeType = item['mimeType'];
if (typeof item.exportLinks != 'undefined') {
if (mimeType == 'application/vnd.google-apps.spreadsheet') {
mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
}
url = item['exportLinks'][mimeType];
link = url;
} else {
lien = item['downloadUrl'].split("&");
link = lien[0] + '&' + lien[1];
url = item['downloadUrl'];
}
title = item['title'];
type = mimeType;
filesize = item['fileSize'];
fileext = item['fileExtension'];
id = item['id'];
var datatable = [url, title, type, filesize, fileext,id];
document.getElementById("myddlink").href=link;
request.open("POST", "downloadfile.php?" + datatable, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.send("datatable=" + datatable);
}
下载文件的功能:
$upload_path='upload_folder';
if (isset($_POST['exportFormat'])) {
$pieces = explode(",", $_POST['exportFormat']);
$url = $_POST['datatable'] . '&exportFormat=xlsx';
$title = $pieces[1];
$type = $pieces[2];
$fileext = $pieces[0];
$fileId = $pieces[5];
}else {
$url = $_POST['datatable'] . '&e=download';
$pieces = explode(",", $_POST['gd']);
$onlytitle = explode(".", $pieces[1]);
$title = $onlytitle[0];
$type = $pieces[2];
$filesize = $pieces[3];
$fileext = $pieces[4];
$fileId = $pieces[5];
}
$fullPath = $upload_path . '/' . $title . '.' . $fileext;
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: " . $type . "");
header("Content-Disposition: attachment; filename=\"" . $title . '.' . $fileext . "\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $filesize);
// folder to save downloaded files to. must end with slash
$destination_folder = $upload_path . '/';
$newfname = $destination_folder . basename($title . '.' . $fileext);
$file = fopen($url, "rb");
if ($file) {
$newf = fopen($newfname, "wb");
if ($newf)
while (!feof($file)) {
fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
ob_end_flush();
Php文件:
Get-WmiObject -query "select DeviceID,PNPDeviceID from Win32_SerialPort"