Welcome to the LimeSurvey Community Forum

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

User uploads image - how to store + show this image in a later question again?

  • Elibelli
  • Elibelli's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #229690 by Elibelli
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting: Version 3.28.3+220315  survey.mms.tu-berlin.de/  Universityserver
Survey theme/template: fruity
==================
Hi there,
I want users to upload an image "X" during the survey. In a later question during the survey the uploaded image "X" has to be shown to the user again.
The question:
-how do I do this?
-Whats the code to store an uploaded image and then to retrieve and show this stored uploaded image to the user later in another question again?

Thank you in advance:)

This is what I tried:
1.(X is the name of the question with the settings "image upload")

2.When I want to show the image in another question I used the following code:
<img alt="" src="{X}" />
{X}
{X.NAOK}
{X.shown}
<img src="{X.shown}" /><img alt="" id="{X}" src="{X}" />


3.But it only Shows the following : (it should show the image "X" instead of meta info stuff. I want the image to appear here again)
[{ "title":"","comment":"","size":"194.7392578125","name":"pic_20180915_183443.jpg","filename":"fu_b2ryk82kxyg3jiv","ext":"jpg" }] [{ "title":"","comment":"","size":"194.7392578125","name":"pic_20180915_183443.jpg","filename":"fu_b2ryk82kxyg3jiv","ext":"jpg" }] [{ "title":"","comment":"","size":"194.7392578125","name":"pic_20180915_183443.jpg","filename":"fu_b2ryk82kxyg3jiv","ext":"jpg" }] 

i need it to show the uploaded image (the user uploads the image during the survey)

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago - 1 year 10 months ago #229702 by Joffm
Hi,
what you call "meta info stuff" is what is stored in the database.
So you can't expect to get more than this when displaying it.

The image itself is not in the database but in the "files" folder of your survey.
 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 10 months ago by Joffm.
The following user(s) said Thank You: Elibelli

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #229738 by Joffm
Well,
there is a way to do this.
But: Not in your university installation.
You need to have access to a server.

Then you do the following:
UL is the upload question
1. with two (hidden) questions of type equation extract the filename and the extension
eqFname: {substr(UL,strpos(UL,'filename')+11,strpos(UL,'ext') - strpos(UL,'filename') -14)}
eqExt: {substr(UL,strpos(UL,'ext')+6,3)}

2. In a question of type "short text" start an ajax-call to a small script that renames the file.
The ajax call may look like this:
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
  $.post('https://www.mafoserver.de/myFolder/renameFile.php' , { sid: "{SID}",  fname:"{eqFname}",  ext: "{eqExt}" },function(data) { 
          $('#question{QID} input[type="text"]').val(data)
  });
});
</script>

You see, you call a small php script that is somewhere on your server and you post 
  • the surveyID
  • the filename
  • the extension

Now the php script
Something like this:
Code:
<?php
$ssid = $_POST["sid"];
$sfname = $_POST["fname"];
$sExt = $_POST["ext"];
 
$sfullname = '../limesurvey/upload/surveys/'.$ssid.'/files/'.$sfname;
$sNewName=$sfullname.'.'.$sExt;
 
$x=rename($sfullname,$sNewName);
 
echo $sfname.'.'.$sExt;
?>

Now you have a valid filename in the "files" folder that you can call in a later question.
1. Upload
 

2. Extraction of filename and extension (only for information, usually hidden)
 

3. The result of the ajax-call (only for information, usually hidden)
 

4. The picture is displayed
 

To be able to download these uploaded files later from your responses you have to rename back again (at the end of the survey)

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Elibelli

Please Log in to join the conversation.

  • Elibelli
  • Elibelli's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 9 months ago #229878 by Elibelli
Found the solution here:
forums.limesurvey.org/forum/can-i-do-thi...-subsequent-question

It works for the university server as well.. only one line of code where it extracts the weird internally given name and in the same line of code this filename is then used to display the image for the user during the runtime of the survey.

I hope it helps someone. I used different keywords and my university advisor found this solution by using different keywords.
The following user(s) said Thank You: Joffm

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago - 1 year 9 months ago #229879 by Joffm
Thank you for sharing this "old" thread.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 9 months ago by Joffm.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose