Does anybody know how to translate either of the following scripts to PHP?

==========
=== ASP ===
==========

<%

base_folder = "c:\inetpub\wwwroot\"

'no changes are required below this point.

PostData = ""
biData = Request.BinaryRead(Request.TotalBytes)
if len(bidata) > 0 then
image_info = Request.ServerVariables("HTTP_CONTENT_DISPOSITION")
image_info_values = split(image_info, "=")
image_name = replace(image_info_values(1), chr(34), "")

For nIndex = 1 to LenB(biData)
PostData = PostData & Chr(AscB(MidB(biData,nIndex,1)))
Next

Set lf = server.createObject("Scripting.FileSystemObject")
Set SaveFile = lf.CreateTextFile(base_folder & image_name , True)
SaveFile.Write(PostData)
SaveFile.Close
end if

%>

===========
=== PERL ===
===========

#!/usr/bin/perl -w

print "Content-Type: text/plain\r\n\r\n";
print "Upload OK\r\n";

open UPLOADFILE, ">C:\\Temp\\upload.txt";
foreach my $variable (keys %ENV) {
print UPLOADFILE $variable, "->", $ENV{$variable}, "\n"; }
my $length = $ENV{'CONTENT_LENGTH'};
my $file_name = $ENV{'HTTP_CONTENT_DISPOSITION'};
$file_name =~ s/^attachment; filename=\"(.*)\"$/$1/;

print UPLOADFILE "length ", $length, "\n";
print UPLOADFILE "name ", $file_name, "\n";
open IMG_FILE, ">C:\\Temp\\$file_name";
binmode(IMG_FILE);
my $buffer;
read(STDIN,$buffer, $length);
print IMG_FILE $buffer;
#chmod 0666, "C:\\Temp\\$file_name";
close(IMG_FILE);
close(UPLOADFILE);

exit 0;