1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| function WebFileSize(URL: string): cardinal;
var
hInet, hURL: HINTERNET;
len: cardinal;
index: cardinal;
begin
result := cardinal(-1);
hInet := InternetOpen(PChar(application.title), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
index := 0;
if hInet <> nil then
try
hURL := InternetOpenUrl(hInet, PChar(URL), nil, 0, 0, 0);
if hURL <> nil then
try
len := sizeof(result);
if not HttpQueryInfo(hURL, HTTP_QUERY_CONTENT_LENGTH or HTTP_QUERY_FLAG_NUMBER, @result, len, index) then RaiseLastOSError;
finally
InternetCloseHandle(hURL);
end;
finally
InternetCloseHandle(hInet)
end;
end; |
Partager