![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
помогите с download.cgi [D7]
Logo © (2006-04-14 06:35:00)Ниже привожу код программы download.cgi. Пытаюсь использовать для скачивания файлов с моего вебсервера фирмы. Для этого в HTMLках вписываю такие строки:
<a href=/scripts/download.cgi?file=/soft/proga1.exe>
<a href=/scripts/download.cgi?file=/soft/proga2.exe>
<a href=/scripts/download.cgi?file=/soft/readme.txt>
Проблема в том, что файл выкачивается не полностью!
Очень надеюсь найти ответ.
Код в студию:
program download;
{$APPTYPE CONSOLE}
uses
SysUtils;
label FinLabel,mBad,mGood;
{$E cgi}
var
sQueryString,sFileName,sTmp,sWWW:String;
fIn:TextFile;
size: Longint;
begin
sWWW:='c:\Inetpub\wwwroot';
sQueryString:=GetEnvironmentVariable('QUERY_STRING');
If length(sQueryString)=0 then goto mBad;
iPos:=Pos('file=',sQueryString);
If iPos=0 then goto mBad
else sFileName:=Copy(sQueryString,6,Length(sQueryString)-iPos);
If Not(FileExists(sWWW+'/'+sFileName)) then goto mBad;
goto mGood;
mBad:
sTmp:='Content-type: text/html';
writeln(sTmp);
writeln;
writeln;
sTmp:='<html>';
writeln(sTmp);
sTmp:='<head>';
writeln(sTmp);
sTmp:='<meta http-equiv="Refresh" Content="5; URL= http://mysite/">'
writeln(sTmp);
sTmp:='<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">';
writeln(sTmp);
sTmp:='<title>Ошибка.</title>';
writeln(sTmp);
sTmp:='</head>';
writeln(sTmp);
sTmp:='<body>Ошибка.</body></html>';
writeln(sTmp);
goto FinLabel;
mGood:
AssignFile(fIn,sWWW+'/'+sFileName);
Reset(fIn);
// size:=FileSize(fIn)*128;
sTmp:='Content-Type: application/octet-stream';
writeln(sTmp);
sTmp:='Content-Transfer-Encoding: binary';
writeln(sTmp);
// sTmp:='Content-Length: '+IntToStr(size);
// writeln(sTmp);
sTmp:='Content-Disposition: attachment; filename='+sFileName;
writeln(sTmp);
writeln;
writeln;
While Not(EOF(fIn)) do begin
Readln(fIn,sTmp);
Writeln(sTmp);
end;
CloseFile (fIn);
FinLabel:
end.
SpellCaster (2006-04-14 17:12:00) [1]Ууууууу.... goto... как все запущено...
Чапаев (2006-04-14 12:06:00) [2]
> writeln(sTmp);
>
> writeln;
> writeln;
Неправильно, должна быть одна пустая строка. Ну и про ReadLn уже сказали.
Dmitrij_K (2006-04-14 08:52:00) [3]Не читай Readln бинарные файлы.
См. TFileStream, FileOpen, CreateFile