Android视频上传到Php服务器?

发布于 2024-10-18 17:57:23 字数 60 浏览 1 评论 0原文

如何将视频或图像文件上传到 php 服务器。请提供一些示例应用程序或源代码以将文件上传到 php 服务器。

How to upload the video or image file to php server.Anyone provide some sample app or source to upload the file in php server please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惜醉颜 2024-10-25 17:57:23

我建议创建一个 AsyncTask 来处理您的上传,然后使用 Apache Libs 向您的服务器执行 POST。我现在有一个系统,可以将图像发布到 Linux 服务器,然后 PHP 接受 POST 并保存图像数据。尝试这样的事情,如果我没记错的话,你需要从 Apache 获取 commons-io jar 和 httpmime jar 。

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;

HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://www.mywebserver.com/upload");

MultipartEntity multipart = new MultipartEntity();
multipart.addPart("photo",bitmapdata);

postRequest.setEntity(multipart);
HttpResponse response = httpClient.execute(postRequest);

InputStream content = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
StringBuilder serverMsg = new StringBuilder();
String line = "";
while((line = reader.readLine()) != null){ serverMsg.append(line + "\n"); }
content.close();

然后在 PHP 中检查 POST 并使用您喜欢的任何库或代码保存图像。我相信您可以轻松调整此代码以发送视频数据而不是照片。

I'd suggest creating an AsyncTask to handle your upload and then use the Apache Libs to do a POST to your server. I have a system in place now that posts images to a Linux server and then PHP accepts the POST and saves the image data. Try something like this, you'll need to get the commons-io jar and the httpmime jar from Apache if I remember correctly.

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;

HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://www.mywebserver.com/upload");

MultipartEntity multipart = new MultipartEntity();
multipart.addPart("photo",bitmapdata);

postRequest.setEntity(multipart);
HttpResponse response = httpClient.execute(postRequest);

InputStream content = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
StringBuilder serverMsg = new StringBuilder();
String line = "";
while((line = reader.readLine()) != null){ serverMsg.append(line + "\n"); }
content.close();

Then over in PHP, check for the POST and save the image using whatever library or code you prefer. I'm sure you could easily adjust this code to send video data instead of a photo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文