hi all 🙂
what i'm trying to do is : i have a html form that sends a post request to a php file. The php file is supposed to forward the post request to a servlet (java), get the answer from the servlet, parse it, and send it back in html. It works really fine as long as i don't post a file.
If i post a file, it reaches the server (actually, the java servlet) - the mutipart is ok, i find all params i passed, but the file (a jpeg usually) is corrupted and can't be read.
That's why i think the problem is on how i encode the image.
My code to encode the image is :
$fd = fopen ($file_server_side, "r");
// and start to write it in args
$args .= "\r\n--".$boundary."\r\n";
$args .= "Content-Disposition: form-data; name=\"".$file_form_name."\"; filename=\"".$file_client_name."\"\r\n";
$args .= "Content-Type: ".$file_type."\r\n\r\n";
while (!feof($fd))
{
$buffer = fgets($fd, 2048);
$args .= $buffer;
}
fclose ($fd);
i tried to add :
// get rid of extra \n\r (if any) $buffer=str_replace(chr(10),"",$buffer);
$buffer=str_replace(chr(13),"",$buffer);
but still it's not working
i also tried (in case some data were wrapped)
$buffer = fgets($fd,filesize($file_server_side));
finally i even tried (instead of the whille loop)
$args.= join("", file($file_server_side));
in any case, the file is corrupted when it arrives 🙁
so if anyone has any idea ..... thanx in advance 🙂