+ 7
PHP image
How to add an image in PHP
19 Réponses
+ 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.
+ 6
But BOYZER D, when I uploaded the image and pasted the link, it didn't work
https://code.sololearn.com/wQA9Lp7z4MaF/?ref=app
+ 6
💗💖Love💖💗, but in this code, an image was added
https://code.sololearn.com/wCTgJFRAGNvG/?ref=app
+ 5
You can add an image in .php file same in .html file
+ 5
What do you mean by path, BOYZER D?
+ 5
💗💖Love💖💗 This is what I sawhttps://www.sololearn.com/post/501796/?ref=app
+ 5
BOYZER D, which website did you upload the image?
+ 5
BOYZER D, thanks
+ 4
BOYZER D, you don't have to upload the images?
+ 4
BOYZER D, please paste the link of the website. I couldn't find it
+ 3
Okay 💗💖Love💖💗
+ 3
Jadene & Kayla Onobun:
https://code.sololearn.com/WW6t4B73kJVz/?ref=app
This will help u
+ 3
I think sololearn php servers not support img files 😞😞
+ 2
Within html tags ☺
+ 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
+ 1
😔😔😔
Kay try but don't gave up
Ok bye all the guys
0
I'm new
0
PHP can use html so load a php image like a html image.
0
Code for unluck a cricket cell