Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6082881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:20:18+00:00 2026-05-23T11:20:18+00:00

I have an image that I upload with a HTTP Post method to my

  • 0

I have an image that I upload with a HTTP Post method to my webserver written in PHP.
My code compresses a bitmap to a jpeg coded byte array and sends that Base64 encoded to the server which decodes, writes it to a file and opens it as a jpg image.

Index.php:

<?php
$base=$_REQUEST['image'];
echo $base;
// base64 encoded utf-8 string
$binary=base64_decode($base);
// binary, utf-8 bytes
header('Content-Type: bitmap; charset=utf-8');
// print($binary);
//$theFile = base64_decode($image_data);
$file = fopen('test.jpg', 'wb');
fwrite($file, $binary);
fclose($file);
echo '<img src=test.jpg>';
?>

and I have an empty 0kb test.jpg in the same directory.

Sometimes I can see the image when I quickly press F5(refresh), but then when I refresh again, the image is removed again and it’s again 0KB. (working on Google Chrome)

1) How can I make that the picture keeps displaying the data written to test.jpg and doesn’t change back to 0kb? So when I view it, the picture is still there. (note that my PHP knowledge is not so good, so instructions would be really much appreciated.)

Upload method in JAVA, Android:

public void uploadFrame(byte[] Frame, String WebClient) {
    String ba1=Base64.encodeBytes(mCurrentFrame);
    ArrayList<NameValuePair> nameValuePairs = new
    ArrayList<NameValuePair>();
       nameValuePairs.add(new BasicNameValuePair("image",ba1));

       try{

           HttpClient httpclient = new DefaultHttpClient();
           HttpPost httppost = new
           HttpPost(WebClient);
           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
           HttpResponse response = httpclient.execute(httppost);
           HttpEntity entity = response.getEntity();
           is = entity.getContent();
     }catch(Exception e){
           Log.e("log_tag", "Error in http connection "+e.toString());
     }
}

2) Another question is, if this method is actually safe because people could send any POST Method data to it and display any picture. So how would this work in PHP to first check if a parameter in JAVA is equal to a parameter in your PHP code, so only people with the same parameter could upload this code to his webserver.

This could be a quite intresting topic for some people.

EDIT:

<?php

    if (isset($_REQUEST['image'])) {
        $base=$_REQUEST['image'];
        echo $base;
        // base64 encoded utf-8 string
        $binary=base64_decode($base);
        // binary, utf-8 bytes
        header('Content-Type: bitmap; charset=utf-8');
        // print($binary);
        //$theFile = base64_decode($image_data);
        $file = fopen('test.jpg', 'wb');
        fwrite($file, $binary);
        fclose($file);
        echo '<img src=test.jpg>';
    }

        header('Content-type: image/jpeg');
        readfile('test.jpg');
    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:20:19+00:00Added an answer on May 23, 2026 at 11:20 am

    Every time you refresh the page, it’s going to write data to that test.jpg file. If you don’t submit a base64 image, it’ll just write out a blank/null string, which means a 0-byte file.

    Instead, try this:

    <?php
    
    if (isset($_REQUEST['image'])) {
       ... your decoding/fopen/fwrite stuff here ...
    }
    
    header('Content-type: image/jpeg')
    readfile('test.jpg');
    

    This will directly output the image as a jpg, rather than outputting HTML and forcing the browser to open yet another HTTP connection to load the .jpg file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image uploader (http://valums.com/ajax-upload/) that uses an iframe as a fallback for
I have an application that uses the Paperclip plugin for image upload. Now that
Here is a controller action method that I have to upload a user's profile
Hi I am integrating the watermark code http://koivi.com/php-gd-image-watermark/ This script works well. But I
I have a desktop application that needs to upload/download images to/from service computer over
I have a really cool website that allows people to upload images. Sometimes there
Let say, I have a web application that allows users to upload images and
i have an image that contains a series of images, e.g.: In the olden
I have an image that I'm rendering like this: glDrawPixels(image->width, image->height, GL_BGR, GL_UNSIGNED_BYTE, image->imageData);
I have an image that I get and attempt to load into a graphics

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.