When we use the event [upload name] to reappoint a file, and when 'menu' > 'upload' - > 'number files on upload' is unchecked, then the file is reappointed well in upload success but not in the reality. because of the line:
if not numberFilesOnUploadChk.checked then exit; , then the last
assignFile(data.f^, data.uploadDest); is never executed.
The code needs to be changed to
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', ['%item-size%','gus '+inttostr(data.conn.post.length)]);
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);
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