note 33663 deleted from function.fsockopen by danbrown

From: Date: Sun, 20 Jul 2008 19:53:26 +0000
Subject: note 33663 deleted from function.fsockopen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142322@lists.php.net to get a copy of this message
Note Submitter: chris at music-server dot com ---- 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 :-)

« previous php.notes (#142322) next »