Displaying image from different disk - php

Hi i want to show images from different disk.
Here is my code.
is it possible to do that ?
$a = "D:/img/1.jpg";
<img src="<?php echo $a; ?>" alt="...">
Im using this on my localhost.This is not for the web.
i add screenshot here.
when i come above the img it shows the link. but not show img. and i use lightbox.
but without lightbox its not show again.
example

The sample you provided/attached is only doable if you load the html file directly to your browser. It is not possible if you load it via localhost. In your case, you will have to do something like this:
<?php
$image = file_get_contents('D:/img/1.jpg');
$image_codes = base64_encode($image);
?>
<image src="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" />
Reference: How to retrieve and show images from another drive using src attribute in <img> tag?

I'd suppose to use such URLs with protocol: $a = 'file:///D:/img/1.jpg';

Related

Display image from outside the web root ( public_html )

Background:
I have a folder with images called uploads or images located outside the website root. ( outside of public_html )
I am trying to print the image inside let's say image.php.
Rules for doing it:
I am trying to do it without using alias mod_rewrite in .htaccess.
Without showing a black background and image in the middle ( I don't want it like when browsing domain.com/image.png. like the example of the picture I mentioned below.
Without using another page and pass it as get.
What I tried:
I checked many questions, one of them is this and another is
this.
From following the current questions asked above and other tutorials, I came up with
this:
<?php
$location = dirname($_SERVER['DOCUMENT_ROOT']);
$image = $location . '/public_html/images/banned.png';
header('Content-Type:image/png');
header('Content-Length: ' . filesize($image));
echo file_get_contents($image);
?>
<img src=" <? echo $image; ?> "/>
It works fine, and here is an example:
Gyazo
However, this is not what I am looking for, or trying to do. Again, I am trying to view it as a normal image src as it will be used for a profile picture or other usages.
Any help will be much appreciated. Thanks in advance!
Change your image.php to
<?php
function image() {
$location = dirname($_SERVER['DOCUMENT_ROOT']);
$image = $location . '/public_html/images/banned.png';
return base64_encode(file_get_contents($image));
}
?>
In another file where you want to display that image, let's say test.php:
<?php
include("image.php");
?>
<img src='data:image/png;base64,<?= image(); ?>' >
This:
echo file_get_contents($image);
?>
<img src=" <? echo $image; ?> "/>
is wrong for a few reasons. First, you cannot mix raw image content with HTML markup that way. Also src specifies the URL of the image not the raw content.
You can either move your echo file_get_contents($image); and related code to separate file, i.e. image.php, then reference it in your src, passing image name as argument (i.e. image.php?img=foo.jpg) - note that if you do this wrong, you will be open to directory traversal attack). Alternatively you can try to use rectory traversal attackdata URI scheme as src argument and pass raw content directly that way.

Load relative path of images instead of <?php echo $img ?>

The timthumb function is not working after the security setting of web server is raised.
Images with "http://...." in URL are blocked.
I have found that <?php echo $img ?> was used to load the image.
Original code:
<img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?h=100&w=100&zc=1&src=<?php echo $img ?>" alt="<?php the_title_attribute(); ?>" width="100" height="100" />
Would someone please tell me how can I modify the code so that instead of
http://domain.com/wp-content/themes/a/scripts/timthumb.php?h=100&w=100&zc=1&src=http://domain.com/wp-content/uploads/thumbnail.jpg
the image URL will be
http://domain.com/wp-content/themes/a/scripts/timthumb.php?h=100&w=100&zc=1&src=../wp-content/uploads/2013/10/thumbnail.jpg
?
The code inside timthumb.php is super long. I will post the code if it's needed.
I know almost nothing about php code and only use plugins to build Wordpress websites.
You would have save my life. Thank you very very much!
It depends on where it is getting $img value from. If this is just a field on your article (through the extra parameters on the bottom), you could simply alter the url in your post. Alternatively, you could process the path, stripping out the http://domain.com/ and replace it with ../,
a la:
$img = str_replace("http://domain.com/", "../", $img);
just before echoing it out on to the page.

How to return an image from own PHP page using other server url

How can I make a PHP page that will return image from other server specified by url in variable, like this:
http://www.mypage.com/MyScript.php?src=http://www.otherpage.com/image.png
And after going to that page an image should apear.
It need to work for any other srcs too.
(Why like this?
I want to try bypass the Security Error that apears using toDataUrl from canvas while using image not from the same domain, by using http://www.mypage.com/MyScript.php?src=http://www.otherpage.com/image.png as a image src used in canvas)
You can try with
echo file_get_contents($_GET['src']);
In MyScript.php, use $_GET['src'] as the source of the image
<img src="<? echo $_GET['src']; ?>" />

Image is not shown in PDF file using dompdf

I am using DOMPDF to convert the html into PDF and after converting I'm sending that PDF file to user mail id.
Everything is working perfectly but in PDF file I am not able to see the image of logo of my site. I also searched in stackoverflow for previous question such as :- error in pdf image using dompdf ,
dompdf and img tag, image wont show
I also set DOMPDF_ENABLE_REMOTE to TRUE and DOMPDF_PDF_BACKEND to CPDF
my image tag is :-
<img src="http://www.example.com/clients/myprojects/images/logo.png" alt="" /></a>
I'm giving full path of my website but still it does not show image in my PDF file.
Thanks in advance.
use full directory path with .jpg image
It works for me.
<img src="<?php echo $_SERVER["DOCUMENT_ROOT"].'/placeholder.jpg';?>"/>
<img src="<?php echo $_SERVER["DOCUMENT_ROOT"].'\placeholder.jpg';?>"/>
<img src="<?php echo $_SERVER["DOCUMENT_ROOT"].'./placeholder.jpg';?>"/>
Don't put full path of URL, just put foldername/filename.jpg
Example:
<img src="uploads/kuruvi.jpg">
I my case i spend 2 hour finally i got answer
img src not working with url or path you should covert it base64 format
<?php
$data = file_get_contents('https://teafloor.com/wp-content/themes/teafloor2-0/assets/images/logo.png');
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
?>
<?php echo '<div class="company-logo">
<img src="'.$base64.'" alt="base" />
</div>';
?>
or
<img src="<?php echo $base64; ?>" alt="base" />
if I recall it correctly you can put there a full system path to that image - absolute or relative to your script
Remove the alt attribute and changing it from a self-closing tag (/>) to a normal one (>). It worked for me.
Note: dompdf seems to have a bad response to any inline styles on img tags, so I suggest removing them if you´re using any.
//use full directory path something like this
$currentsite = getcwd();
$html = <<<HTML
<html>
<img src="{$currentsite}/sites/all/modules/certificate_handler/image002.png" alt="" /></a>
</html>
HTML;
I did this:
$imgurl = $graficas[$i];
$path_parts = pathinfo($imgurl);
$graficas[$i] = $path_parts['filename'].".jpg";
And works. I hope this would help you too
DOMPDF
working now with png,jpg.
here what I used.
I have index.php file in route folder and image in subfolder namely images.
$image ="images/".$_FILES['image_index_name']['name'];
$htm= '';
You just have to change the line def("DOMPDF_ENABLE_REMOTE", FALSE); to true in the file DOMPDF_CONFIG.INC
Now latest DOMPDF version another, but have the same problem on PHP v5.3
Upgrade to v5.4 or higher
The problem has solved.
I think you could add this
private function change_url_image($data,$url){
$str=$url; //for example "http://localhost/yoursite/";
$str2=str_replace($str,"",$data);
return $str2;
}
to change url for image it's very simple

Thumbnail image does not appear on website

I have a problem in my wordpress theme.
The thumbnail doesn't appear on every post.
I have a website with games and every game has a thumbnail (image) . But now the image doesn't appear. When I try to see the image I get this:
Invalid src mime type:
The problematic code is:
<img src="<?php bloginfo('template_url');?>/thumb.php?src=<?=$thumb;?>&w=183&h=140&zc=1" class="thumb" alt="<?php the_title(); ?>" />
What might be wrong?
Browsing to your site I saw what the issue is. If you look at your code, it's being generated like this:
<img src="http://jocuri2k.com/wp-content/themes/Games/thumb.php?src=<?=$thumb?>... ?>
It seems that your PHP parser isn't picking up the php in the tag. Try using this instead:
<img src="http://jocuri2k.com/wp-content/themes/Games/thumb.php?src=<?php=$thumb?>... ?>
It's possible your php configuration doesn't allow for "short-tags"
<?
code here
?>
but instead require the full php tags, which are:
<?php
code here
?>
You might be able to override this in your php.ini, but if you don't have access to that, simply use the full php tags and you should be good to go.
<?php echo $thumb; ?>

Categories