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

  • Home
  • SEARCH
  • 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 7431021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:13:52+00:00 2026-05-29T09:13:52+00:00

These are the steps: POST Form (file/image input) from the browser goes to a

  • 0

These are the steps:

  • POST Form (file/image input) from the browser goes to a PHP server.
  • The PHP server then use fsockopen to a Java (GlassFish/Jersey) REST service, sending the image as content for more advanced imaging work to be done there, and returning the resulting image back to the PHP server (or returning only a URI to the image).
  • The PHP server then echos the result (img src= ..) back to the user in the HTML document.

Getting the image and all its attributes in the first step works great, but I need help setting up the headers correctly in the POST request from PHP to the web service.

Current code:

$fp = fsockopen("domain..", 80, $errno, $errstr, 30);
$contentlength = $_FILES["photo_file"]["size"];
$imageref = $_FILES["photo_file"]["tmp_name"];

$out = "POST /Uri to resource .. HTTP/1.1\r\n";
$out .= "Host: http://... \r\n";
$out .= "Connection: Keep-Alive\r\n";
$out .= "Content-type: multipart/mixed\r\n";
$out .= "Content-length: $contentlength\r\n\r\n";
$out .= "$imageref";

fwrite($fp, $out);
$theOutput;
while (!feof($fp))
{
  $theOutput .= fgets($fp, 128);
}
echo $theOutput;
fclose($fp);

Which echoes to the browser: “HTTP/1.1 400 Bad Request Content-Type: text/html Content-Length: 717”.

So I need better formed headers to get through to the REST web-method. And if I should achieve that does anyone know what paramaters to use in the jersey web-method to access the image?
For standard HTML forms its this:

@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response getFullImage(@FormDataParam("photo_file") InputStream imageIS {..ImageIO.read(imageIS)..}

Would love suggestions to better architecture also for achieving this in HTML.

Cheers

  • 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-29T09:13:52+00:00Added an answer on May 29, 2026 at 9:13 am

    You probably have problem with badly written request and should use cURL at first place (in php), basic example usage (with writing to the file) from manual page:

    $ch = curl_init("http://www.example.com/");
    $fp = fopen("example_homepage.txt", "w");
    
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    

    Another example for setting post data from curl_setopt() page:

    $data = array('name' => 'Foo', 'file' => '@/home/user/test.png');
    
    curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    

    And handling HTTP status codes via curl_getinfo():

    if(curl_getinfo($c, CURLINFO_HTTP_CODE) === 200){
        ...
    }
    

    You also may set http headers manually:

    curl_setopt($cURL,CURLOPT_HTTPHEADER,array (
            "Content-Type: text/xml; charset=utf-8",
            "Expect: 100-continue"
        ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say,how to implement these three steps: 1.fetch a html source from server side 2.use
I currently filter some message from my inbox with these steps: select inbox pick
I simply want to upload an image to a server with POST. As simple
<form method=post action=/Order/CheckOut/ onSubmit=return Validate()> and then... function Validate() { alert($(#email).val()); return false; }
I made a discovery some time back. Just follow these steps: Create a .doc/.xls/.ppt
User registration in my application is performed in steps. After submitting the form, some
How can I use addEventListener() to assign a handler to an HTML form's Submit
I'm using the jquery tokeninput plugin from loopj.com Here is my JS File: $(document).ready(function()
I have tried two different implementations for simulating POSTing a form. One uses fsockopen
I have a multipart Rails form that includes a Paperclip attachment. When I post

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.