This topic is locked

Displaying json images after uploading

3/30/2020 8:13:50 AM
PHPRunner General questions
W
william_teale author

I am having real trouble decoding the json content of a field in my database.
I used phprunner 10.3 to create a page where multiple images can be uploaded at the same time, the info being stored in a text field. Everything seems to work perfectly (images upload, text stored in field properly) until I try to decode it using php on the web page.
The code I am using is as follows...



<?php
$someArray = json_decode($Recordset1->getColumnVal("OTHER_IMAGES"), true);
foreach ($someArray as $key => $value) {

echo "<div class=\"col-md-4\" style=\"margin-bottom: 5px\" ><a href=\"" . $value["name"] . "\" class=\"fancybox img-hover-v2\"><span><img src=\"" . $value["thumbnail"] . "\" class=\"img-fluid\"></span></a> </div>";

}

?>


When I run the same code, with the content of the field entered into the code, it works just as intended.



<?php
$fulljson = '[{"name":"..\/vendor_images\/01_3fzd5wkh.png","usrName":"01.png","size":118406,"type":"image\/png","thumbnail":"..\/vendor_images\/th01_u5f3fl6s.png","thumbnail_type":"image\/png","thumbnail_size":118406,"searchStr":"01.png,!02.png,!03.png,!:sStrEnd"},{"name":"..\/vendor_images\/02_5tkaoqv1.png","usrName":"02.png","size":125586,"type":"image\/png","thumbnail":"..\/vendor_images\/th02_jjj5ro58.png","thumbnail_type":"image\/png","thumbnail_size":125586},{"name":"..\/vendor_images\/03_bp34jgek.png","usrName":"03.png","size":108485,"type":"image\/png","thumbnail":"..\/vendor_images\/th03_cp7ofn1w.png","thumbnail_type":"image\/png","thumbnail_size":108485}]';
$someArray = json_decode($fulljson, true);
foreach ($someArray as $key => $value) {

echo "<div class=\"col-md-4\" style=\"margin-bottom: 5px\" ><a href=\"" . $value["name"] . "\" class=\"fancybox img-hover-v2\"><span><img src=\"" . $value["thumbnail"] . "\" class=\"img-fluid\"></span></a> </div>";

}



?>


When I run the php var_export() I get the full text I expected in the field



'[{&quot;name&quot;:&quot;..\&#x2F;vendor_images\&#x2F;01_3fzd5wkh.png&quot;,&quot;usrName&quot;:&quot;01.png&quot;,&quot;size&quot;:118406,&quot;type&quot;:&quot;image\&#x2F;png&quot;,&quot;thumbnail&quot;:&quot;..\&#x2F;vendor_images\&#x2F;th01_u5f3fl6s.png&quot;,&quot;thumbnail_type&quot;:&quot;image\&#x2F;png&quot;,&quot;thumbnail_size&quot;:118406,&quot;searchStr&quot;:&quot;01.png,!02.png,!03.png,!:sStrEnd&quot;},{&quot;name&quot;:&quot;..\&#x2F;vendor_images\&#x2F;02_5tkaoqv1.png&quot;,&quot;usrName&quot;:&quot;02.png&quot;,&quot;size&quot;:125586,&quot;type&quot;:&quot;image\&#x2F;png&quot;,&quot;thumbnail&quot;:&quot;..\&#x2F;vendor_images\&#x2F;th02_jjj5ro58.png&quot;,&quot;thumbnail_type&quot;:&quot;image\&#x2F;png&quot;,&quot;thumbnail_size&quot;:125586},{&quot;name&quot;:&quot;..\&#x2F;vendor_images\&#x2F;03_bp34jgek.png&quot;,&quot;usrName&quot;:&quot;03.png&quot;,&quot;size&quot;:108485,&quot;type&quot;:&quot;image\&#x2F;png&quot;,&quot;thumbnail&quot;:&quot;..\&#x2F;vendor_images\&#x2F;th03_cp7ofn1w.png&quot;,&quot;thumbnail_type&quot;:&quot;image\&#x2F;png&quot;,&quot;thumbnail_size&quot;:108485}]'


There are no errors in the console. A link to the output mentioned can be seen here
Can anybody see what I have done wrong, or offer another method for decoding the json?

Admin 3/30/2020

The problem is with $Recordset1->getColumnVal("OTHER_IMAGES")
I have no idea what it is, but you are not defining $Recordset1 variable anywhere so it won't work.