Android的视频上传到PHP服务器?服务器、视频、Android、PHP

2023-09-05 04:36:12 作者:一心居一人

如何上传视频或图像文件到PHP server.Anyone提供一些示例应用程序或源代码上传的文件在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.

推荐答案

我建议创建一个AsyncTask的处理上载,然后使用Apache利布斯做一个POST到服务器。我有一个适当的系统,现在张贴图片到Linux服务器,然后PHP接受的POST和保存图像数据。尝试这样的事情,你需要得到的commons-io的JAR和从Apache httpmime罐子,如果我没记错的话。

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();

然后在PHP中,检查POST和使用任何图书馆或code您preFER保存图像。我敢肯定,你可以很容易地调整这个code发送的照片,视频数据来代替。

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.