procedure getUploadDestinationFileName();
var
i: integer;
fn, ext, s: string;
begin
new(data.f);
fn:=data.uploadSrc;
data.uploadDest:=f.resource+'\'+fn;
assignFile(data.f^, data.uploadDest );
// see if an event script wants to change the name
s:=eventToFilename('upload name', []);
if validFilepath(s) then // is it valid anyway?
begin
if pos('\', s) = 0 then // it's just the file name, no path specified: must include the path of the current folder
s:=f.resource+'\'+s;
// ok, we'll use this new name
data.uploadDest:=s;
fn:=extractFileName(s);
// one "assignFile(data.f^, data.uploadDest);" was missing here
end;
if not numberFilesOnUploadChk.checked then exit;
begin
ext:=extractFileExt(fn);
setLength(fn, length(fn)-length(ext));
i:=0;
while fileExists(data.uploadDest) do
begin
inc(i);
data.uploadDest:=format('%s\%s (%d)%s', [f.resource, fn, i, ext]);
end;
end;
assignFile(data.f^, data.uploadDest);
end; // getUploadDestinationFileName