我对php有点陌生。我尝试在 android 中制作一个从 eClass 平台下载文件的应用程序。我开发了这个脚本:
<?php
$code=$_GET['code'];
$code = stripslashes($code);
$code = mysql_real_escape_string($code);
$filename=$_GET['filename'];
$filename = stripslashes($filename);
$filename = mysql_real_escape_string($filename);
$path = "C:\\xampp\\htdocs\\openeclass-2.5\\courses\\".$code."\\dropbox\\".$filename;
$fullPath = $path.$_GET['download_file'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); //
use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
?>
它在从浏览器(在我的本地主机中)调用时下载文件,并将代码和文件名作为 url 中的参数。现在我想在我的 android 应用程序中构建一个调用这个脚本的函数,获取文件并将其保存在 sd 卡中的某个位置
我怎样才能做到这一点?也可以在模拟器中完成吗?先感谢您!