SitePoint Enthusiast
ASP/Perl to PHP Conversion
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;
SitePoint Enthusiast
The data is sent by a network camera with a scaled down LINUX Kernel via a cgi script, so I have no control on how the image is sent. I am able to view the data with the help of the getallheaders() function that contains the following array values:
("Basic cm9vdDpzYXZ5Y2F0X2Jvb3N0ZXI=", "attachment; filename=image02048.jpg", "12389", "image/jpeg", "shttpclient $Revision: 1.28 $", "a", "s").
Can an uploader class handle this data and do you have the script?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks