Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Link to an uploaded file

  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 1 week ago #266392 by mcovents
Link to an uploaded file was created by mcovents
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.5.9
Own server or LimeSurvey hosting: Own server
Survey theme/template: Fruity
==================
I want to link to the file that was uploaded by the user in the previous question.
I inserted the following code in a text question (Type X).
<a href="{G01Q02.file}">Click here to download</a>
But when I run the survey I see the message "Unknown variable"
 
Attachments:

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 1 week ago - 1 month 1 week ago #266394 by Joffm
Replied by Joffm on topic Link to an uploaded file
Hi, you have to consider several things.
1. {G01Q02.file}
".file" is not a LimeSurvey property.
See here
[url] manual.limesurvey.org/ExpressionScript_-...#Access_to_variables [/url]

2. When you only display the content of {G01Q02} you see something like this
 
Among others there is a "name"; this is the original name of the uploaded file. And there is a "file-name" ("fu_" and some random characters)
And if you have a look at the "files" folder of the survey you will see that the files are stored with this "file-name" without extension.
 

Meaning you can't open this file out of the box.

A way I described in my "Tutorial 3: Gimmicks", Chapter 16.2. f. is to rename this "fu-..." file to a usable name 
You find it in the German part, page 13.
BTW: Now I think it to be better to rename to the original name and store in a different folder.

I used an ajax call like this
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
  $.post('https://www.myServer/renameFile.php' , { sid: "{SID}", fname: "{eqFname}", ext: "{eqExt}" },function(data) {                 $('#question{QID} input[type="text"]').val(data)
     });
});
</script>

And in a small php script "renameFile.php" I renamed the file and returned the new name.
Now you can use it to show the file.

Upload
 

And a later display.
 

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 month 1 week ago by Joffm.

Please Log in to join the conversation.

  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 1 week ago #266395 by mcovents
Replied by mcovents on topic Link to an uploaded file
Thank you!
Best regards,
Marc.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose