Attachments - need help in modifying the code (formula)

I use the following code in order to display only the attachment files my users attach on their websites (by excluding multimedia files to be displayed, .jpg, .gif, .wmv etc).

attNames := @LowerCase(@AttachmentNames);

allowedExt := “.doc”:“.pdf”:“.xls”:“.ppt”:“.rar”:“.zip”:“docx”: “xlsx”:“pptx”:“ACCDB”;

aref := “”;

aref1 := “<a href="” + @Text(@DocumentUniqueID) + “/$file/”;

aref2 := “" target="_blank" class="simplelink"><img border=0 hspace="4" src=…/”;

aref3 :=

“word.gif Alt="Click here: Open the Word file" title="Click here: Open the Word file">”:

“pdf.gif Alt="Click here: Open the PDF file" title="Click here: Open the PDF file">”:

“excel.gif Alt="Click here: Open the Excel file" title="Click here: Open the Excel file">”:

“ppt.gif Alt="Click here: Open the Powerpoint presentation" title="Click here: Open the Powerpoint presentation">”:

“rar.gif Alt="Click here: Download the RAR file" title="Click here: Download the RAR file">”:

“winzip.gif Alt="Click here: Download the ZIP file" title="Click here: Download the ZIP file">”:

“docx.gif Alt="Click here: Open the Word file" title="Click here: Open the Word file">”:

“xlsx.gif Alt="Click here: Open the Excel file" title="Click here: Open the Excel file">”:

“pptx.gif Alt="Click here: Open the Powerpoint presentation" title="Click here: Open the Powerpoint presentation">”:

“ACCDB.gif Alt="Click here: Download the Access file" title="Click here: Download the Access file">”;

@For(m := 1; m <= @Elements(allowedExt); m := m + 1;

ext := allowedExt[m];

@For(n := 1; n <= @Elements(attNames); n := n + 1;

newAref := @If(@Contains(attNames[n]; ext); aref1 + attNames[n] + aref2 + @Replace(ext; allowedExt; aref3) + attNames[n] + “
”; “”);

@If(newAref != “”; aref := aref : newAref; “”)));

aref := @Trim(aref);

@For(m := 1; m <= @Elements(aref); m := m + 1; aref[m]);

@Implode(aref;" ")

However, when I attach docx, pptx, xlsx and ACCDB files they appear on the page two times, once with the “doc” and once with the “docx” image in front of the attachment name.

I would appreciate it if someone could fix this issue as I don’t know what I am doing wrong. Also, is it possible to modify the code and instead of the attachment name the custom title (given by the user) to be displayed as well as the file size of each attached file ( (File Size: " + @Text(@Round(@AttachmentLengths/1004;0,01)) ).

Thanking you in advance.

Nana

Subject: Attachments - need help in modifying the code (formula)

“.docx” contains “.doc”. “.docx” != “.doc”. ACCDB files will not appear, since ACCDB can’t show up in an all-lower-case file name. Oh, and if you ever go to a Linux server (rather than a Windows server), your links won’t work because Linux is case-sensitive.

You’d need another multivalue text field in order to allow the users to specify their own link text. It would have to contain both the filename and the link text in each entry in the field (with an easily-identifiable separator between them), otherwise there would be no easy way to relate the filename to the text.

Subject: RE: Attachments - need help in modifying the code (formula)

Many thanks Stan for your always valuable assistance and comments.

I understood the logic behind the “.docx” contains “.doc”. “.docx” != “.doc” however, I don´t know how to fix the code, I presume it is at this section:

@For(n := 1; n <= @Elements(attNames); n := n + 1;

newAref := @If(@Contains(attNames[n]; ext); aref1 + attNames[n] + aref2 + @Replace(ext; allowedExt; aref3) + attNames[n] + “
”; “”);

Could you be of any further assistance please?

Thanks once again in advance.

Subject: RE: Attachments - need help in modifying the code (formula)

You’re using @Contains. @Contains(“some_random_filname.docx”; “.doc”) returns @True, as does @Contains(“some_random_filname.docx”; “.docx”), so you get duplicates. You can use either @Ends or @RightBack and an equality check to get around the “contains” problem. And using:

@If(@Lowercase(@RightBack(attnames[n]; “.”)) = “doc”);…)

in your check also means that you don’t need to change the case of the filename, so your formula becomes Linux-safe.

Subject: RE: Attachments - need help in modifying the code (formula)

Thanks a lot Stan, the problem has been fixed, the code was not working with @RightBack so I tried and replaced the @Contains with the @Ends and it seems to work so far. Thanks once again.