Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android发布到php无法正常工作_Php_Android - Fatal编程技术网

android发布到php无法正常工作

android发布到php无法正常工作,php,android,Php,Android,我有一个android应用程序,它可以将数据发布到php Web服务,如果它从android应用程序发布到php Web服务,它就不能按预期工作,如果相同的数据从html页面发布到php Web服务,它就可以正常工作 php脚本中不起作用的部分如下所示: function makeThumb($src, $dest, $desired_width) { /* read the source image */ $imgsrc = explode('.',$src,-1); $imgdest

我有一个android应用程序,它可以将数据发布到php Web服务,如果它从android应用程序发布到php Web服务,它就不能按预期工作,如果相同的数据从html页面发布到php Web服务,它就可以正常工作

php脚本中不起作用的部分如下所示:

function makeThumb($src, $dest, $desired_width) {

/* read the source image */ 
$imgsrc =   explode('.',$src,-1);
$imgdest    =   explode('.',$dest,-1);
$dest   =   $imgdest[0].'Thumb.png';
$source_image = imageConvert($src, $dest,0);



list($width, $height, $img_type, $img_attr) = getimagesize($dest);

//$width = imagesx($source_image);
//$height = imagesy($source_image);

/* find the "desired height" of this thumbnail, relative to the desired width  */
$desired_height = floor($height * ($desired_width / $width));

/* create a new, "virtual" image */

$virtual_image = imagecreatetruecolor($desired_width, $desired_height);

imagealphablending($virtual_image, false);
/* copy source image at a resized size */
$source_image = imagecreatefrompng($source_image);
//imagealphablending($source_image, false);

imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);

/* create the physical thumbnail image to its destination */
imagealphablending($virtual_image,false);
imagesavealpha($virtual_image,true);
imagepng($virtual_image, $dest);

}
从android发布到php文件的代码如下:

protected void onActivityResult(int requestCode, int resultCode,
        Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    // ::

    File tempFile = getTempFile();

    String filePath = Environment.getExternalStorageDirectory() + "/"
            + TEMP_PHOTO_FILE;
    System.out.println("path " + filePath);

    Bitmap bitmap = BitmapFactory.decodeFile(filePath);

    // Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream); // compress to
                                                            // which format
                                                            // you want.
    byte[] byte_arr = stream.toByteArray();
    String image_str = Base64.encodeBytes(byte_arr);
    final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    //nameValuePairs.add(new BasicNameValuePair("action", "uploadImage"));
    nameValuePairs.add(new BasicNameValuePair("image", image_str));
    nameValuePairs.add(new BasicNameValuePair("sociochatU",
            IMService.USERNAME));
    nameValuePairs.add(new BasicNameValuePair("sociochatP",
            IMService.password));
    nameValuePairs.add(new BasicNameValuePair("mpf",
            "true"));

    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(
                        SocketOperator.AUTHENTICATION_SERVER + "includes/inc.upload.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                final String the_string_response = convertResponseToString(response);
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(UserProfile.this,
                                "Response " + the_string_response,
                                Toast.LENGTH_LONG).show();
                    }
                });

            } catch (final Exception e) {

                System.out.println("Error in http connection "
                        + e.toString());
            }
        }

    });

    t.start();

}
activityresult上的受保护无效(int-requestCode、int-resultCode、,
意图(返回内容){
super.onActivityResult(请求代码、结果代码、图像返回内容);
// ::
File tempFile=getTempFile();
字符串filePath=Environment.getExternalStorageDirectory()+“/”
+临时照片文件;
System.out.println(“路径”+文件路径);
位图位图=BitmapFactory.decodeFile(文件路径);
//位图位图=位图工厂.decodeFile(picturePath);
ByteArrayOutputStream=新建ByteArrayOutputStream();
compress(bitmap.CompressFormat.PNG,90,stream);//压缩到
//哪种格式
//你想要的。
byte[]byte_arr=stream.toByteArray();
字符串image\u str=Base64.encodeBytes(byte\u arr);
最终ArrayList nameValuePairs=新ArrayList();
//添加(新的BasicNameValuePair(“操作”、“上传图像”);
添加(新的BasicNameValuePair(“image”,image_str));
添加(新的BasicNameValuePair(“SocialChatu”),
IMService.USERNAME);
添加(新的BasicNameValuePair(“SocialChatp”),
IMService.password);
添加(新的BasicNameValuePair(“mpf”),
“真实”);
线程t=新线程(新的可运行线程(){
@凌驾
公开募捐{
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(
SocketOperator.AUTHENTICATION_SERVER+“includes/inc.upload.php”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
最终字符串\u字符串\u响应=convertResponseToString(响应);
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
Toast.makeText(UserProfile.this,
“响应”+字符串响应,
Toast.LENGTH_LONG).show();
}
});
}捕获(最终异常e){
System.out.println(“http连接错误”
+e.toString());
}
}
});
t、 start();
}
我在HTML中用于发布到同一php文件的代码如下:

<form method="POST" action="SocketOperator.AUTHENTICATION_SERVER & "includes/inc.upload.php" target="_blank">

<input name="sociochatU" id="sociochatU" value=""/><br/>
    <input name="sociochatP" id="sociochatP" value=""/><br/>
    <input name="mpf" id="mpf" value="true"/><br/>
<textarea name="image" id="base64"></textarea><br/>
<input type="submit" name="Submit" id="Submit" value="Submit"/><br/>

在此处发布代码后立即发现问题


我注意到android应用程序正在将图像压缩为PNG图像,在服务器端,它将其分配为JPG文件,并将php文件上的代码更改为分配PNG扩展名。成功了

那么,实际发布的是什么?你查过了吗?http服务器错误日志文件说了什么?您目前正在猜测可能发生的情况。改为查看和阅读。@arkascha实际发生的情况是,它确实将base64代码发布到服务器上,并在服务器端使用android应用程序和html代码创建一个图像。但是,只有html代码在创建THUMB,而android代码却没有。让我如此困惑的是,php文件正在做所有的工作,其他2个文件只是发布图像。但是,errorlog文件中没有任何内容