我做了一个应用程序,这可以下载文件格式的服务器。如何使用PHP强制下载在Android上下载文件
使用此代码>>>
public int startDownload(String url, String filename) {
// create url connector
URL u;
byte[] buffer = new byte[1024];
try {
u = new URL(url + filename);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
InputStream in = c.getInputStream();
m_lMaxDownloadSz = c.getContentLength();
FileOutputStream f = new FileOutputStream(new File(FILE_PATH, filename));
m_bCancelDownload = false;
m_lCurrentDownloadSz = 0;
int len = 0;
while ((len = in.read(buffer, 0, 1024)) > 0) {
// if download is canceled.
if (m_bCancelDownload) {
f.close();
c.disconnect();
return FILE_DOWNLOAD_CANCELED;
}
if (knot++ >= PROGRESS_STEP) {
knot = 0;
myProgressDialog.setProgress(GetDownloadStatus());
}
f.write(buffer, 0, len);
m_lCurrentDownloadSz += len;
}
f.close();
c.disconnect();
} catch (Exception e) {
return FILE_DOWNLOAD_FAILED;
}
if (GetDownloadStatus() == 100) {
return FILE_DOWNLOAD_FINISHED;
} else {
return FILE_DOWNLOAD_FAILED;
}
}
,我想用PHP力下载使用,但它不能正常工作,一般它像“应用程序/ aaa.apk文件路径中使用' 这行得通! ,我改变为PHP文件,如'php/forcedl.php'它不起作用。
我需要用php强制下载,我该如何使用?
ps。我有一点英语语言技能,使英语不是我的主要语言
谢谢
如果您尝试在浏览器中打开此URL,会发生什么情况? –
我在android浏览器中打开www.xxx.com/x.php,它显示提交以下载file.apk ps。在文件php>标头强制下载到一个apk文件 – chawanan