This topic is locked
[SOLVED]

 Show image from url in databse field

1/14/2016 9:36:08 AM
PHPRunner General questions
S
snuffi01 author

Hi!
I cant figure this out...
I have an mysql table and on eof the fields contain url to pictures (in this case avatar from Linkedin).

On Edit and View page i would lik eto show the picture (i dont need to be able to edit the value, just show the picture).

The field containing the url is called "AvtarURL"
I have tried to add an "PHP Code snippet"

with the following code:



if ($data["AvtarURL"] == ""){

$value="images/avtar_3.png";

}

$value = "<img width=75 height=75 src='".$data["AvtarURL"]."'>";
header('Content-type: image/png;');
$p = ($value);

$a = file_get_contents($p);

echo $a;


But the picture wont show up <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=23587&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />

Admin 1/14/2016

I guess you need to drop this part:



header('Content-type: image/png;');
$p = ($value);

$a = file_get_contents($p);

echo $a;
S
snuffi01 author 1/14/2016



I guess you need to drop this part:



header('Content-type: image/png;');
$p = ($value);

$a = file_get_contents($p);

echo $a;



Hi,
Tried to drop that parts but still same problem (no picture on edit page)

code in "PHP code snippet" now:



if ($data["AvtarURL"] == ""){

$value="images/avtar_3.png";

}

$value = "<img width=75 height=75 src='".$data["AvtarURL"]."'>";
S
snuffi01 author 1/14/2016

Can anyon ehelp me with this one?
The code i have right now is



if ($data["AvtarURL"] == ""){

$value = "images/avtar_3.png";

}

$value = "<img width=75 height=75 src='".$data["AvtarURL"]."'>";

echo $value;


With this code (inserted as "PHP Code snippet" on Edit page), i get an "Broken" image icon.

When inspecting the element i can see that the url of th eimage is $data and not the url of the field AvtarURL or if AvtarURL the image images/avtar_3.png
Anyone?

Admin 1/14/2016

This code won't make much sense as a "Code snippet". In code snippet there is no $data array to access. It will work as a part of 'View as' Custom code.

S
snuffi01 author 1/15/2016

Ok, then i understand why it doesnt work.

Is there any way to accomplish what i want in an edit page?

Admin 1/15/2016

On Edit page simply set 'Edit as' type as readonly. It will display your image.

S
snuffi01 author 1/16/2016



On Edit page simply set 'Edit as' type as readonly. It will display your image.


Thanks!

That did solve my problem.

Together with following code on "Custom"



if ($data["AvtarURL"] == ""){

$value="images/avtar_3.png";

}

$value = "<img width=75 height=75 src='".$data["AvtarURL"]."'>";