Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file encoding to POST

Status
Not open for further replies.

iza

Programmer
Apr 4, 2000
1,804
FR
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 ...
 
the answer was VERY stupid : i just had to use fread instead of the while/fgets
now just wondering why didn't anyone answer :
- the question was too obvious
- the question was too tough ?
- you didn't understand my problem ??
- you hate me ;)))))
i mean, i'm REALLY wondering now ;]]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top