HTML PHP Image URL Call - php

I have an image URL, for example, http://URL/123.jpg. I can view the image in the browser, but it's not working when using the <img> tag in PHP. It's not working, and the idea is somehow not displayed.
echo "<img src=\"http://URL/123.jpg\" style=\"width:11%;height:auto;margin-left: 570px;margin-top: 170px;\">";
Any idea?

For php I use '' and for html the "" quotation marks.
Don't know if it's gonna solve your issue tho. Maybe the height:auto; is the problem. I think you can even delete it, if you set the width the height should be auto by default.
echo '<img src="http://test.com/123.jpg" style="width:11%;margin-left: 570px;margin-top: 170px;" />';

Use Normal HTML syntax, include your php then save file as .php
<!DOCTYPE html>
<html>
<body>
<img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.GONAZbNLqDhBj8q4CpTnCQHaLH%26pid%3DApi&f=1" style="width:100px;height:auto;margin-left: 570px;margin-top: 170px;"/>
<!--your php file-->
<?php include 'footer.php';?>
</body>
</html>
Don't forget you have to save this file as PHP.

Related

How can I insert a PHP generated PNG image into my html?

I'm generating a png image using php that works here:
http://www.sidesay.co/BTC_spark.php
However I am attempting to then insert the generated png file into a table on a webpage (I'm unsure if that's terribly inefficient). I use the php line:
echo "<td><img src=\"https:\/\/www.sidesay.co\/BTC_spark.php\" ></td>";
I get a broken image, but if I right click and select "load image" it works.
Should I instead first run the php file and save the image separately before destroying it? If so, how?
Thanks in advance.
Your BTC_spark.php script is outputing HTML itself:
<html>
<body>
<img src='/libraries/Sparkline/sparkline.php?size=80x20&data=2,4,5,6,10,7,8,5,7,7,11,8,6,9,11,9,13,14,12,16&back=fff&line=5bb763&fill=d5f7d8' />
</body>
</html>
Change it to just output the img src:
/libraries/Sparkline/sparkline.php?size=80x20&data=2,4,5,6,10,7,8,5,7,7,11,8,6,9,11,9,13,14,12,16&back=fff&line=5bb763&fill=d5f7d8
... and then in your main script, stick this output in a variable:
$mypic = file_get_contents('./BTC_spark.php');
echo '<td><img src="'.$mypic.'"></td>';

How to embed a pdf in HTML and print that with cmd+p / ctrl+p

I am trying to include a pdf file in my HTML page and allow users to print that by using cmd+p or ctrl+p.
Here is my code -
<html>
<body>
<p> I want to print this page with pdf </p>
<iframe src="/my.pdf" width="800px" height="2100px" />
</body>
<html>
When I visit my page I am able to see the pdf file but when I try to print it shows me a blank page for pdf.
I am building this application with PHP. I have tried the embed and object tag also but had no luck with this.
Please help me to fix this.
Such functionality is not possible as explained here: Print Pdf from javascript embed tag
The only real thing you can do is try to convert the PDF to images and use the "#media print" tag to style the printing page appropiately.
It's a different matter
Record it for others.
If there are a lot of blank pages, the class you want to print out:
#media print{
.paper {
display:inline-block
}
}
Apply above CSS. My problem solve by this trick.

output image in php page

thank you so much for your hard work,
my issue hopefully is not that complicated.
I'm trying to display few images in my website, and it won't display,
the php page and the image are on the same directory, and when i try the same directory on html file it works fine, but when I try to use the same directory on php file the pic look broken icon,and won't appear..
I also tried png and jpg image, still nothing coming out..
please guys..
this is the simple code, i tried to test,
<html>
<head><title> hello </title></head>
<body>
<?php $image = 'zz.png'; ?>
<img src= "<?php $image ?>" style="width:304px;height:228px;">
hello world..
</body>
</html>
Print the var $image with echo (and close the image tag with a frontslash at the end of the tag for correct html):
<img src= "<?php echo $image; ?>" style="width:304px;height:228px;" />
Other possible reasons the image is not displayed (after you print the image name out with echo):
the value of your var $image mismatched with the imagename.
the image is not stored in the same folder as the php document.
your image is saved in CMYK mode, and not in RGB.
the file permission of the image
configuration of the webserver (apache for ex.)
You have to print out the $image variable by using the echo function. Your code should be looking like this:
<?php
$image = 'zz.png';
?>
<html>
<head>
<title> hello </title>
</head>
<body>
<img src= "<?php echo $image; ?>" style="width:304px;height:228px;">
hello world..
</body>
</html>
Furthermore, it looks better when you put all your php stuff before the HTML code, that does not necessarily have to be inside HTML.
If it is still not working, you are probably viewing your html file locally. You have to view it remotely by using a http web server with a php interpreter included. You can easily set up one with XAMPP.
Remember that it does not work by just opening your file in a browser.
I think you should replace this line:
<img src= "<?php $image ?>" style="width:304px;height:228px;">
With this:
<img src= "<?php echo($image) ?>" style="width:304px;height:228px;">
Since echo() is the function that generates the output.

Display images like logo in .php file with html img tag

I am very new to PHP where the same issue have been facing. Coding a simple welcome php page with a logo in png or jpg format does not show in both development and production server.
Tried using changing the permissions to the folders and files but nothing results.
Any idea?
to do this, you could simply include a PHP echo code segment in your HTML file. for instance,
<html>
<div id="banner">
<?php echo '<image src="logo.jpg" />'; ?>
</div>
</html>
I've used this code to display my logo:
echo "<img src="https://yangtzesolutions.com/wp-content/uploads/2021/07/logo-150x150.png" <?php imageResize(100,100, 150); ?>>";
It will display image from the source URL: https://yangtzesolutions.com/wp-content/uploads/2021/07/logo-150x150.png

Adding a bar above a full screen PDF

I'm currently displaying a PDF using header type application/pdf and readfile for the pdf itself.
I need to add a bar at the top of the pdf with a button on.
The issue is that the PDF is currently the whole screen and there is any html behind it.
Is there a way this can be done?
I've looked on google but can't find a way this has been done?
Thanks.
You can use an <iframe>. You put your regular HTML followed by the <iframe> pointing to your PDF file. Something like this:
<html>
<head>
<title>Sample</title>
</head>
<body>
<div style="width:100%;height:50px;">Top Bar with a <button>here</button></div>
<iframe src="pdffile.php" style="width:100%;"></iframe>
</body>
</html>

Categories