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

2 days 11 hours 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 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}" />
<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.

2 days 8 hours ago - 2 days 8 hours ago #229702 by Joffm
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.


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 days 8 hours ago by Joffm.

Please Log in to join the conversation.

1 day 8 hours ago #229738 by Joffm
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:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
  $.post('' , { sid: "{SID}",  fname:"{eqFname}",  ext: "{eqExt}" },function(data) { 
          $('#question{QID} input[type="text"]').val(data)

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:
$ssid = $_POST["sid"];
$sfname = $_POST["fname"];
$sExt = $_POST["ext"];
$sfullname = '../limesurvey/upload/surveys/'.$ssid.'/files/'.$sfname;
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)


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now