+ 7

PHP image

How to add an image in PHP

22nd Aug 2020, 11:44 AM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
26 Respostas
+ 7
How are images uploaded in PHP(not related to Sololearn's Code Playground)? Images are just a specific type of file so you can upload them like this: https://www.w3schools.com/php/php_file_upload.asp How are images added on Sololearn's Code Playground? You can't add images to Sololearn's Code Playground when using the PHP language without really weird workarounds. The reason it doesn't work appears to be that the the script's outputs are merely echoed out into the body of a web page. Normally, the complete HTTP response can be controlled by the PHP script so the script can say to output a PNG image( through the Content-type HTTP header ) and give the raw data. The following script would work in a normal web hosting environment but Sololearn's Code Playground merely shows the raw binary data in markup of a web page: <?php header("Content-type: image/png"); $path = 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Facebook_Logo_%282019%29.png/1024px-Facebook_Logo_%282019%29.png'; $type = pathinfo($path, PATHINFO_EXTENSION); $data = file_get_contents($path); echo $data; Something like this works in Sololearn's Code Playground: <img src="data: image/png;base64,<?php $path = 'https://mineblocks.com/1/wiki/images/f/f8/SantaHat.png'; $type = pathinfo($path, PATHINFO_EXTENSION); $data = file_get_contents($path); echo rawurlencode(base64_encode($data)); ?>" style="width: 100px;height:100px"> You can add them in HTML/CSS/JS based on answers at: https://www.sololearn.com/Discuss/1924077/can-we-add-images-in-sl If you want PHP to draw images, PHP's GD functions are great. Some details are at: https://www.php.net/manual/en/book.image.php That can be useful if you want to watermark uploaded images, scale them, or convert image formats.
23rd Aug 2020, 12:45 PM
Josh Greig
Josh Greig - avatar
+ 6
But BOYZER D, when I uploaded the image and pasted the link, it didn't work https://code.sololearn.com/wQA9Lp7z4MaF/?ref=app
22nd Aug 2020, 12:19 PM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
22nd Aug 2020, 12:29 PM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
+ 5
You can add an image in .php file same in .html file
22nd Aug 2020, 11:52 AM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 5
What do you mean by path, BOYZER D?
22nd Aug 2020, 12:08 PM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
22nd Aug 2020, 12:38 PM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
+ 5
BOYZER D, which website did you upload the image?
22nd Aug 2020, 1:20 PM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
+ 5
BOYZER D, thanks
22nd Aug 2020, 1:22 PM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
+ 4
BOYZER D, you don't have to upload the images?
22nd Aug 2020, 12:04 PM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
+ 4
BOYZER D, please paste the link of the website. I couldn't find it
22nd Aug 2020, 1:27 PM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
22nd Aug 2020, 12:34 PM
Kayla Onobun (QOG)
Kayla Onobun (QOG) - avatar
22nd Aug 2020, 1:26 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 3
I think sololearn php servers not support img files 😞😞
23rd Aug 2020, 1:49 AM
꧁•☬₣ℜøźєη•ᴵᴰ☬•꧂
꧁•☬₣ℜøźєη•ᴵᴰ☬•꧂ - avatar
+ 2
Within html tags ☺
24th Aug 2020, 11:31 AM
Bob
Bob - avatar
+ 1
I am Boyzer D Kay my account and ip address now blocked .. Why my account blocked i don't know But kay now i will never meet with u Sorry I send my answer to the sololearn official website sorry kay i will not help more Bye guys
24th Aug 2020, 5:22 AM
SHIBGAT
SHIBGAT - avatar
+ 1
😔😔😔 Kay try but don't gave up Ok bye all the guys
24th Aug 2020, 5:26 AM
SHIBGAT
SHIBGAT - avatar
0
I'm new
24th Aug 2020, 9:02 AM
Ahmad Shah
0
PHP can use html so load a php image like a html image.
30th Oct 2020, 10:25 AM
Cleen
Cleen - avatar
0
Code for unluck a cricket cell
25th Nov 2020, 10:31 AM
Mary Rangel
Mary Rangel - avatar