File Upload Emulation To A Remote Server With POST
| From: | Chris Lambert | Date: | Tue, 22 Aug 2000 09:09:56 +0000 |
| Subject: | File Upload Emulation To A Remote Server With POST | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-12903@lists.php.net to get a copy of this message | ||
This one's been killing me. First, let me briefly describe my setup. My main
website is run on an NT/IIS server. The server doesn't have PHP installed on
it, therefore rendering it difficult for me to do any development. My
solution is to make and host my PHP scripts off-server, and then come up
with some way to transfer the output to the remote server.
I've tried fopen(...,"w") as well as the FTP functions, but there seems to
be a problem with IIS not conforming to the FTP standard, and therefore
refusing file put's. Get, directory listings, and everything else works
fine -- but it won't allow me to send. My last resort is putting an ASP
script on the main server which allows file uploading.
I've avoided ASP components, and found a script which lets you upload binary
and ascii files through a form using <input type=file>. This works great
when using IE/Netscape as a client, but I'd like to be able to do it with
PHP (for obvious reasons.) So, I tried fsockopen -- but the ASP script
doesn't seem to want to "bite" with the data I'm sending it. Therefore, this
is directed at anyone who knows a little VBScript along with PHP. VBScript
is pretty easy to pick up just by looking at it, so others might be able to
give it a shot. Here is the HTML code which works when posting to the script
via a browser:
<FORM ENCTYPE="multipart/form-data" ACTION="upload.asp" METHOD=POST>
<INPUT TYPE="file" NAME="file1">
<INPUT TYPE="Submit" VALUE="Submit">
</FORM>
The code for upload.asp is quite extensive and can be found at:
http://www.planetunreal.com/about/stallion/asp.txt
The PHP code (non-working) I was using is:
<?
function PostToHost($host, $path, $data) {
$fp = fsockopen($host,80);
fputs($fp, "POST $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: ".strlen($data)."\n");
fputs($fp, "Connection: close\n\n");
fputs($fp, "file1 = $data");
while(!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
So, after spending a few hours looking at the code and possible things I did
wrong -- I only know a little more. It seems like the code sent needs to be
different for a file upload. Has anyone done a server-to-server file upload?
If so, can you help me out?
Thanks for reading, and for any help I can get on this one...
Chris «Stallion» Lambert - clambert@gamespy.com
ModCentral/PlanetUnreal - www.planetunreal.com