hi
i've got a problem with the encoding of image files :
i have a form that posts to one of my php classes
i want this class to forward the request to my server (and to parse the answer, which is actually why i designed this class - but to intercept the answer i first have to forward the request !)
if i pass a jpeg image, it gets corrupted when it finally reaches the sever (but the multipart and the names of variables are all fine, just the CONTENT of the file)
that's why i think the problem is in the encoding of the file
here is the code i use to encode it : (variables are all ok)
$fd = fopen ($file_server_side, "r"
// args is the multipart
$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, 4096);
$args .= $buffer;
}
fclose ($fd);
i've also tried (but it's not working any better)
* $buffer = fgets($fd, filesize($file_server_side));
(in case some lines were too long)
* also
// get rid of extra \n\r (if any)
$buffer=str_replace(chr(10),"",$buffer);
$buffer=str_replace(chr(13),"",$buffer);
* and even, not using buffer and not doing a while :
$args.= join("",file($file_server_side));
and if i send the same request with the same image to the same server using only the 'form' or another script (in perl this one) everything is fine
so if anyone has any idea ...
i've got a problem with the encoding of image files :
i have a form that posts to one of my php classes
i want this class to forward the request to my server (and to parse the answer, which is actually why i designed this class - but to intercept the answer i first have to forward the request !)
if i pass a jpeg image, it gets corrupted when it finally reaches the sever (but the multipart and the names of variables are all fine, just the CONTENT of the file)
that's why i think the problem is in the encoding of the file
here is the code i use to encode it : (variables are all ok)
$fd = fopen ($file_server_side, "r"
// args is the multipart
$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, 4096);
$args .= $buffer;
}
fclose ($fd);
i've also tried (but it's not working any better)
* $buffer = fgets($fd, filesize($file_server_side));
(in case some lines were too long)
* also
// get rid of extra \n\r (if any)
$buffer=str_replace(chr(10),"",$buffer);
$buffer=str_replace(chr(13),"",$buffer);
* and even, not using buffer and not doing a while :
$args.= join("",file($file_server_side));
and if i send the same request with the same image to the same server using only the 'form' or another script (in perl this one) everything is fine
so if anyone has any idea ...