Post method question again.

From: Date: Wed, 02 Aug 2000 09:31:29 +0000
Subject: Post method question again.
Groups: php.general 
Request: Send a blank email to php-general+get-9657@lists.php.net to get a copy of this message
Thanks a lot! I read rfc 1867 and wrote following php script. <? $fp = fsockopen("www.samplehost.com", 80, &$errno, &$errstr ) ; // send request fputs( $fp, "POST /test/file_up.html HTTP/1.0\r\n") ; fputs( $fp, "content-type:multipart/form-data, boundary=AaB03x\r\n\r\n") ; fputs( $fp, "--AaB03x\r\n") ; fputs( $fp, "content-disposition: form-data;name=\"userfile\";filename=\"samplefile.txt\"\r\n") ; fputs( $fp, "content-type:text/plain\r\n") ; // content of samplefile.txt $userfile = fopen( "samplefile.txt", "r") ; fputs( $fp, fread( $userfile, filesize("samplefile.txt") ) ); fputs( $fp, "--AaB03x--\r\n") ; fputs($fp, "\r\n") ; // print the response while( ! feof( $fp ) ) echo fread( $fp, 256 ) ; fclose( $fp ) ; ?> but it doesn't work. Server response is : HTTP/1.1 200 OK Date: Wed, 02 Aug 2000 09:09:06 GMT Server: Apache/1.3.12 (Unix) PHP/3.0.15 X-Powered-By: PHP/3.0.15 Connection: close Content-Type: text/html <br> <b>Warning</b>: fopen("","r") - No such file or directory in <b>/www3/htdocs/test/file_up.html</b> on line <b>6</b><br> <br> <b>Warning</b>: Unable to find file identifier 0 in <b>/www3/htdocs/test/file_up.html</b> on line <b>6</b><br> RFC 1867 says like this : 6. Examples Suppose the server supplies the following HTML: <FORM ACTION="http://server.dom/cgi/handle" ENCTYPE="multipart/form-data" METHOD=POST> What is your name? <INPUT TYPE=TEXT NAME=submitter> What files are you sending? <INPUT TYPE=FILE NAME=pics> </FORM> and the user types "Joe Blow" in the name field, and selects a text file "file1.txt" for the answer to 'What files are you sending?' The client might send back the following data: Content-type: multipart/form-data, boundary=AaB03x --AaB03x content-disposition: form-data; name="field1" Joe Blow --AaB03x content-disposition: form-data; name="pics"; filename="file1.txt" Content-Type: text/plain ... contents of file1.txt ... --AaB03x-- If the user also indicated an image file "file2.gif" for the answer to 'What files are you sending?', the client might client might send back the following data: Content-type: multipart/form-data, boundary=AaB03x --AaB03x content-disposition: form-data; name="field1" Joe Blow --AaB03x content-disposition: form-data; name="pics" Content-type: multipart/mixed, boundary=BbC04y --BbC04y Content-disposition: attachment; filename="file1.txt" Page 10 Content-Type: text/plain ... contents of file1.txt ... --BbC04y Content-disposition: attachment; filename="file2.gif" Content-type: image/gif Content-Transfer-Encoding: binary ...contents of file2.gif... --BbC04y-- --AaB03x-- ---------------------------------------------- What's my mistake! [InoS] --MIME Multi-part separator--

« previous php.general (#9657) next »