简体   繁体   English

使用php和android将文件(pdf,doc,jpg,png)上传到我的本地服务器

[英]Upload file(pdf,doc,jpg,png) to my local server using php with android

I want to select file from my device(android) then upload in local server using php and save its path to my database . 我想从我的设备(android)中选择文件,然后使用php上传到本地服务器并将其路径保存到我的数据库 Next i want to download it from that upload location. 接下来,我想从该上传位置下载它。 how can I do this ? 我怎样才能做到这一点 ? help me. 帮我。

I would use a http request to your php server here is a full working example: http://androidexample.com/Upload_File_To_Server_-_Android_Example/index.php?view=article_discription&aid=83&aaid=106 我会向您的php服务器使用一个http请求,这里是一个完整的工作示例: http : //androidexample.com/Upload_File_To_Server_-_Android_Example/index.php?view=article_discription&aid=83&aaid=106

To have the client download I would make a /download.php file and use a get parameter to set the database pk to the url they wanna download. 要下载客户端,我将制作一个/download.php文件,并使用get参数将数据库pk设置为他们想要下载的url。 next I would read the file and then use the header to change the PHP's output to file so it causes the client to download via http. 接下来,我将读取文件,然后使用标头将PHP的输出更改为文件,以使客户端通过http下载。

CODE EXAMPLE: 代码示例:

$attachment_location = "filePath";
if (file_exists($attachment_location)) {
    header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
    header("Cache-Control: public"); // needed for internet explorer
    header("Content-Type: application/zip");
    header("Content-Transfer-Encoding: Binary");
    header("Content-Length:".filesize($attachment_location));
    header("Content-Disposition: attachment; filename=filePath");
    readfile($attachment_location);
die();
} else {
    die("Error: File not found.");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM