尝试上传图像时,base64_decode返回null

I am trying to upload an image to server but base64_decode always returns null i read a lot of different cases from SO but nothing works. here is my java code before i make my http request:

      ByteArrayOutputStream stream = new ByteArrayOutputStream();
            // Must compress the Image to reduce image size to make upload easy
            bitmap.compress(Bitmap.CompressFormat.PNG, 50, stream); 
            byte[] byte_arr = stream.toByteArray();
            // Encode Image to String
            encodedString = Base64.encodeToString(byte_arr,Base64.NO_WRAP);
            params.add(new BasicNameValuePair(TAG_IMAGE, encodedString));
           ...and the http request

php code:

                     $base=$_REQUEST['image'];
                          //$response["base"] = $base;
                       $binary=base64_decode($base,TRUE);
                          $response["binary"] = $binary;
                         header('Content-Type: bitmap; charset=utf-8'); 
                         $imagepath='the path of the image';
                            $file = fopen($imagepath, 'w');
                            fwrite($file, $binary);
                            fclose($file);

i also tried $file = fopen($imagepath, 'wb'); still $binary is always return with null; somebody can please help me understand what is the problem?

also i checked $base and it looks ok, i also tried to remove or \\ but nothing helps

so i figure it out: 1. the path that you need to save the image must be relative to the web service (php code in my case) in the server which also mean you have to save the image at the same server. 2. file_put_contents is a lot easyier to use and replace the fopen, fwrite and fclose together and save you trubble. i hope it will help you guys