Let's say I have a url of an image link location that doesn't have an extension (.jpg) but when I go to the url it shows me that the corresponding link is an image? How would echo this url in php?
For example the recaptcha image from recaptcha.net it encodes the string with a public key. When I make an html file and use it outputs the image on the page, but when I try to echo the same attributes in php it just outputs a blank image and doesn't display the google captcha image. I am trying to create a forum login page for vbulletin but in this case it should use the captcha implementation since I don't want to sign up for crawling with bots on the my page by google. Can anyone tell me how I can go about doing this?
So basically after the request is made to obtain the key from the image which is assigned to $key the echo request doesn't output the image:
$key = the data inside the GET parameter 'c' everytime the captcha is requested.
echo "<img src='www.google.com/recaptcha/api/image?c=".$key."'/>";
You can use a image regardless of the file extension. It's the MIME type that matters.
The reason why the following won't work is because of no specified protocol.
<img src="goo.gl/XWyGjO"/>
Working:
<img src="//goo.gl/XWyGjO"/>
<img src="http://goo.gl/XWyGjO"/>
<img src="https://goo.gl/XWyGjO"/>
// = inherit the current protocol.
Related
I want to make an email-signature page with Elementor and then generate the HTML-code like the code when you that appears when you "View Source" of a page, but code gets not exactly correct. I am using a Custom post type and a Elementor template that is not published so it works only when writing: https://mysite123123.com/a/site/?theme_template_id=1164
I have a PHP snippet plugin and this code gets the Post type HTML but not the same like when you press rightclick/View Source. (Its missing some css etc)
Can you see what Im doing wrong or if you know how to echo the correct html from a webpage like a regular visitor see it?
(Im using this code to give a user a HTML signature)
<?php
global $wp;
$vpost = get_post($post_id);
$urlcard = $vpost->post_name;
$current_url = home_url( $wp->request );
$data = file_get_contents("https://mysite123123.com/a/".$urlcard."/?theme_template_id=1164");
$html_encoded = htmlentities($data);
echo $html_encoded;
You can tell the browser how it should render your data using a Content-Type HTTP Response header.
To have your data rendered as plain text -- as the 'View source' view does -- use "text/plain" as mime-type;
header("Content-Type: text/plain");
echo $data
I'm trying to connect to the database and view pictures from there. Despite the fact that all pictures are shown, it is not possible to download them. To download I use tag .
Here is my code.
while($row = mysqli_fetch_array($result))
{
echo '
<tr>
<td align="center">
<a href="data:image/jpeg;base64,'.base64_encode($row['Pilt'] ).'" download>
<img src="data:image/jpeg;base64,'.base64_encode($row['Pilt'] ).'" width=400 class="img-thumnail" />
</a>
</td>
</tr>
';
}
Here is a small part of the database where I get pictures. https://imgur.com/yZGsFzb . So I noticed that only one photo is being downloaded, which size is 150.4KiB.
I expect that by clicking on the image (any size) it will be downloaded. Right now when I click on image appears error like this https://imgur.com/yZrlIH8 whereas I would like to see something like this https://imgur.com/4vkUukp .
I will be very grateful for any help.
I recommend you stop printing large quantities of big images that way, they will be hardcoded in the HTML code and downloaded all at once to the browser's cache, 2 times (3 with the click included). This wastes RAM and bandwidth. The network error you get is probably caused by the abnormally big size of the href in your link (might even look a bit like malware to your browser).
Instead, you want to serve these images dynamically on a PHP script first (by setting the header to 'Content-Type: image/png' and printing the image contents as obtained from your database) and provide a direct URL to the script.
This example works just as described in your screenshots, I'm indicating where you should replace your SQL queries to obtain the image:
while(for all your rows)
{
echo '
<tr>
<td align="center">
<a href="image.php?id=' . $id . '" download>
<img src="image.php?link=' . $id . '" width=400 class="img-thumnail" />
</a>
</td>
</tr>';
}
And image.php would look something similar to:
<?php
$id = htmlspecialchars($_GET['id']);
header('Content-Type: image/png');
$content = store the image contents from the BD here ($row['Pilt'] in your code);
echo $content;
Notice that image.php serves images dynamically and I'm supposedly identifying each image with an id (perhaps your row id? You can think of more secure identifiers too if ids are not public already). This is a common security practice in PHP so that you're not providing absolute file paths or other information to attackers.
I'm working on task of share a link on facebook. But I want to display my own static image (independent of url). With help of google and facebook, I come to know that I have to pass image path (which I want to display) in image parameter of sharer.php. But still, it displays image related to that site. I don't know that where is my mistake. If anyone know answer then please explain or suggest me link from where I can understand from beginning. Thank You.
Here is my code.
<?php
$title = urlencode("How to Create a Custom Facebook Share Button with a Custom Counter");
$url = urlencode("http://www.daddydesign.com/wordpress/how-to-create-a-custom-facebook-share-button-with-a-custom-counter/");
$summary = urlencode("Learn how to create a custom Facebook 'Share' button, complete with a custom counter, for your website!");
$image = urlencode("http://www.daddydesign.com/ClientsTemp/Tutorials/custom-iframe-share-button/images/thumbnail.jpg");
?>
<html>
<a id="button" onClick="window.open('http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title; ?>&p[summary]=<?php echo $summary; ?>&p[url]=<?php echo $url; ?>&&p[images][0]=<?php echo $image; ?>', 'sharer', 'toolbar=0,status=0,width=550,height=400');" target="_parent" href="javascript: void(0)">
Click to Share
</a>
</html>
Your image http://www.daddydesign.com/ClientsTemp/Tutorials/custom-iframe-share-button/images/thumbnail.jpg is the problem - it's not actually an image but takes you to a regular webpage.
You need to set a specific image which fits facebook's size requirements, the minimum size is 200x200 pixels.
I'm trying to unobtrusively detect when JavaScript is disabled by having an image inside of a noscript element. I'm pretty sure I'm on the right path though I'm not sure about what data I should be echoing exactly.
<noscript><img alt="" src="images/noscript.gif" /></noscript>
The base64 encoded data below is simply a 1x1 transparent GIF image.
header('HTTP/1.1 200');
header('Content-type: image/jpeg');
echo 'data:image/gif;base64,R0lGODlhAQABAIAAAP8A/wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
What do I need to do to ensure I can have PHP intercept the image request and have the image successfully be displayed on the page (obviously while JavaScript is disabled)?
<noscript><img alt="" src="path_to_script.php"/></noscript>
Script:
header('HTTP/1.1 200');
header('Content-type: image/gif');
echo base64_decode('R0lGODlhAQABAIAAAP8A/wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
You could just make the src attribute the link of the PHP file:
<noscript><img alt = "" src = "[stuff].php" /></noscript>
Also, I don't know how PHP servers work, but in Python TCPServers and UDPServer, the server is run by a class with this handle() method that takes in data from the client and then sends data back. That data can be completely independent then the actual file from that link.
If this is the same in PHP, then you could get a request for a link from images/noscript.gif, not even have a images/noscript.gif file, and then just send back the data from the PHP file.
Ah, I forgot I can decode the image at the server. The key is having the client make an HTTP request otherwise the server won't be aware and thus can not log that JavaScript is disabled.
<?php
header('HTTP/1.1 200');
header('Content-type: image/gif');
echo base64_decode('R0lGODlhAQABAIAAAP8A/wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
?>
I have developped a brower plugin that Acquire a picture from a Scanner or a Camera and save the picture in the file system of the user.
The output is the filepath to the picture.
I want to preview the picture in the Broswer, using javascript...
How can I get the picture without user interaction ?
( part of a Web App only compatible with Google Chrome)
If you have the filepath returned by your browser plugin and you have identified the event when you have to display the image then you can call ShowImage(filepath) function on that event.
<script type="text/javascript">
function ShowImage(filePath) {
$("#preview").append("<img alt='img' src='" + filePath + "'");
}
</script>
Your HTML should contain the div:
<div id="preview"></div>
If you have the contents of the image already you can load them in directly, by base64 encoding it and providing an URL as follows:
<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />