Image uploads and HTML in text fields

arcadeicons

Member
A couple of small issues.

1.) How do I get the url for uploaded images from a sql query? There's lots of info in that field, but I need the url to use the picture in an article.

2.) My text areas dont seem to be saving any formatting, I assume I'm missing a setting on the element but only see the retian HMTL option under truncate which I assume is only related to that.
 
1 - it depends how your upload element is configured. if you are using cropping, with a single AJAX upload, you'll have a JSON data structure in the field, like:

Code:
[{"file":"\\images\\stories\\crop_test\\2015-02-25_1952_-_Copy.png","params":"{\"rotation\":0,\"scale\":100,\"imagedim\":{\"x\":200,\"y\":200,\"w\":1266,\"h\":849},\"cropdim\":{\"x\":200,\"y\":200,\"w\":300,\"h\":300},\"crop\":true,\"modalId\":\"fileupload-modal-fab_crop_test___crop_test-widget-mocha\",\"quality\":0.9,\"mainimagedim\":{\"x\":200,\"y\":200,\"w\":1266,\"h\":849}}"}]

... and I don't think you can extract the path from that in a query, you have to decode the data in PHP after the query.

For all other cases - not cropped, or cropped but with multiple AJAX (so it creates a one-to-many table to put the data in) the field should just contain the relative path (from the J! root) for the file.

2 - probably your J! text filter settings, not a Fabrik thing. I think the default is to strip out most HTML.

-- hugh
 
Hrmmm.

OK yep it was the text filters in Joomla so that was an easy enough fix.

As for the images, I need to be able to use the uploaded image in an article as it is used for a classified ad. I am using the Ajax upload (doesn't show pictures in the form btw), just for 1 picture at the moment with no cropping but it still seems to use the data structure you showed above.

Researching a little I found the JSON decode option, assuming the photo JSON object is stored at select_game.game_photo

Code:
$gameID = 614

$strSQL = "
SELECT s.game_photo
FROM select_game s
WHERE id = $gameID";

$myJson=mysql_fetch_assoc($sql);
$pictureinfo = json_decode($myJson);
$picture = $pictureinfo->'file';

Print ('<img src="'.$picture.'" />');

should give me the image, but my output is <img src="/">
 
Last edited:
Something is tripping me up, here is the content of s.game_photo when I do my var_dump of $game_photo

Code:
[{"file":"\/images\/Flynn\/cf37e4eb2f56761930bb1d621a89020e.jpg","params":"{\"rotation\":0,\"scale\":100,\"imagedim\":{\"x\":244,\"y\":399,\"w\":432,\"h\":576},\"cropdim\":{\"w\":100,\"h\":100,\"x\":240,\"y\":360},\"crop\":false,\"modalId\":\"fileupload-modal-select_game___game_photo-widget-mocha\",\"quality\":0.9,\"mainimagedim\":{\"x\":244,\"y\":399,\"w\":432,\"h\":576}}"}]

but trying to process this with json_decode($game_photo); just crashes and renders nothing
 
well that was fun...

Code:
 $jsonDecodedData = json_decode($game_photo, true);

$pictureinfo = $jsonDecodedData[0];

$property = 'file';

$picture = $pictureinfo[$property];
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top