rejetto forum

procedure getUploadDestinationFileName()

Mars · 1 · 6457

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2063
    • View Profile
 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

Quote
 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

« Last Edit: July 28, 2009, 09:31:25 AM by Mars »