note 33663 added to function.fsockopen

From: Date: Thu, 03 Jul 2003 11:53:10 +0000
Subject: note 33663 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-51428@lists.php.net to get a copy of this message
I also needed a file upload via fsockopen and tried to work with Chris Snyders posting above: ======================== POST /path/to/script.php HTTP/1.0 Host: example.com Content-type: multipart/form-data, boundary=AaB03x Content-Length: $requestlen --AaB03x content-disposition: form-data; name="field1" $field1 --AaB03x content-disposition: form-data; name="field2" $field2 --AaB03x content-disposition: form-data; name="userfile"; filename="$filename" Content-Type: $mimetype Content-Transfer-Encoding: binary $binarydata --AaB03x-- ========================== I discovered some weird behaviour on my Linux server with PHP 4.0 and wanted to let you know :) 1) Lines needed to end with \r\n (else the last character of the value was cropped) 2) I needed to remove Content-Type and Content-Transfer-Encoding from the binary "userfile" - else the uploaded file contained these strings and was invalid! 3) The receiving script couldn't reference to the variables $field1 although register_globals was switched on! Needed to work with $HTTP_POST_VARS['field1'] and $HTTP_POST_FILES['userfile'] to get the values. o.k., here's the script sending the header: $f=fsockopen($server,80,$errno,$errstr,30); fwrite($f,$header); fclose($f); The receiving script is as easy :) The file was uploaded to $HTTP_POST_FILES['userfile']['tmp_name'] and the variables were named as mentioned above. Hope, it prevents spending another afternoon to figure out a file-upload this way :-) ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33663 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33663&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33663&report=yes

« previous php.notes (#51428) next »