Welcome to the LimeSurvey Community Forum

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

Present previously uploaded image in subsequent question

  • ybanens
  • ybanens's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 10 months ago #169217 by ybanens
Hi folks,

I have a client who would like to allow respondents to upload an image of themselves, then present them with a modified (aged) version of that image in a subsequent survey.

Is there a way to use Expression Manager to generate the URL for a stored image, based on a participant's token?

First, I'd like to part-prove the concept by letting a participant upload an image, then showing it back to them in a subsequent question. I tried creating one question with the code FILEUPLOAD, then populating the question text of a second question with {FILEUPLOAD}, but it returned only the metadata about the image, i.e.
Code:
[{ "title":"","comment":"","size":"141.447","name":"unityLogo.png","filename":"fu_3xtte3n3g8fhcxg","ext":"png" }]

Can anybody help me with either the first part of the question (show an image back to someone after they've uploaded it) or the whole problem (show an image to someone in a different survey, that they uploaded in another)?

Thanks very much
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 10 months ago #169228 by tpartner
Regarding the first part - have a look at this post about how to parse the returned Expression manager value - www.limesurvey.org/forum/can-i-do-this-w...uploaded-file#122453 .

So, if the upload question code is "upload1" and only one upload is allowed, you could use an <img /> tag like this:

Code:
<img src="../upload/surveys/{SID}/files/{stristr(str_replace('filename":"', '', stristr(upload1, 'filename":"')), '"', 'true')}" />

Sample survey attached:

File Attachment:

File Name: limesurvey...4455.lss
File Size:14 KB



Regarding the second part, you cannot access data from a previous survey.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: ybanens
The topic has been locked.
  • ybanens
  • ybanens's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 9 months ago - 5 years 9 months ago #169363 by ybanens
Thanks very much tpartner.

The code doesn't seem to parse correctly for me when it's embedded in an IMG tag. I can successfully pull the attributes of the file using the example snippets you provided, but it stops working once it's in the IMG tag.

You can see in the code colouring in the attached screenshot that the parser stops treating it as a string after the second double-quotes and it doesn't start again on the third one.

When the question is saved and closed, the code gets mangled and saved in the wrong order, as follows :-
This:
Code:
<img src="../upload/surveys/{SID}/files/{stristr(str_replace('filename":"', '', stristr(FILEUPLOAD, 'filename":"')), '"', 'true')}" />
Becomes this:
Code:
<img :="" src="../upload/surveys/{SID}/files/{stristr(str_replace('filename" />

(Note: My upload question is called FILEUPLOAD)

Do you have any insights into what may be going wrong?
Last edit: 5 years 9 months ago by ybanens.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #169378 by tpartner
Try without using the HTML editor.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #169379 by tpartner
BTW, did my sample survey work when imported without modification?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • ybanens
  • ybanens's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 9 months ago #169386 by ybanens
I'm in a managed environment and don't have the ability to import LSS files. I did try opening the file with a text editor and grabbing the code out of there, with the same result.

Pardon my ignorance, but I don't see where to change out of the HTML editor! You don't just mean switching to source? There may be some settings hidden from me in this environment.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #169387 by tpartner

Pardon my ignorance, but I don't see where to change out of the HTML editor!

Open your personal settings and switch the HTML editor mode.


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose