我想将图片文件上传到我的PHP网络服务。
我做了一些requestID s for my webservice but i don
知道如何将正确的requestID发送到我的PHP服务。
图片上传是requestID 7。 如何添加requestID或我需要更改哪些内容才能使其正常工作?
Android代码
public void triggerImageUpload() {
makeHTTPCall();
}
// Make HTTP call to upload Image to webservice.
public void makeHTTPCall() {
prgDialog.setMessage("uploading....");
AsyncHttpClient client = new AsyncHttpClient();
//Change link here. client
client.post("#URL",
params, new AsyncHttpResponseHandler() {
// When the response returned by REST has Http
// response code '200'
@Override
public void onSuccess(String response) {
// Hide Progress Dialog
prgDialog.hide();
Toast.makeText(getApplicationContext(), "Done.",
Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(Foto1.this, Foto2.class);
Foto1.this.startActivity(myIntent);
}
PHP代码
if(isset($_POST['requestID']))
{
$requestID = $_REQUEST['requestID'];
if($requestID = 1)
{
//empty
}
if($requestID = 7)
{
// Get image string posted from Android App
$requestID = $_REQUEST['requestID'];
$base=$_REQUEST['image'];
// Get file name posted from Android App
$filename = $_REQUEST['filename'];
// Decode Image
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
// Images will be saved under 'uploads' folder
$file = fopen('uploads/'.$filename, 'wb');
// Create File
fwrite($file, $binary);
fclose($file);
echo 'Image upload complete, Please check your php file directory';
}