I have a bit of code that, using php, I want it to call in an image rather than what it is currently calling in (which is 'echo bloginfo('name');). However, I am sadly PHP illiterate and have no idea how to do this with the 'a href' posted below. Could anyone help me call to /images/logo.png? Many thanks in advance!
<h1><?php echo bloginfo('name'); ?></h1>
The tag for add images is <img src=""> on the srcattribute you need to write the url of the image you want (in your case /images/logo.png) so, replacing the code you pasted
<h1><img src="/images/logo.png"></h1>
Take into account that the path to the image you are using now is a relative one (relative to the document requiring the image) so you probably want to have the absolute url instead.
...place at the beginning of you webpage, near the top with the rest of your PHP/JavaScript:
<?php
$image_name = '/images/logo.png';
?>
...In this are you place allof your HTML...
<img src='<?php echo $image_name; ?>'>
Basically, you can have a variable named 'image_name' that you can have be anything.
If you wanted the HREF link area to be a variable that could be changed as well, just do this:
<?php
$image_name = '/images/logo.png';
$image_url = 'http://www.google.com';
?>
Then...
<a href='<?php echo $image_url; ?>' border='0'><img src='<?php echo $image_name; ?>'></a>
What is the return of get_settings() function? ==> name's Image?
I think this code is OK, but you should check the return value of your function.
Related
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.
As I am retrieving a column of content in html form, from database as this column contain text and image which is retrieved through base url();
see example:
<p>Although the complexities, individualities and uniqueness of the human mind is beyond
imagination, let alone comprehension.</p>
<img src="<?php echo base_url(); ?>assets/uploads/guide-banner.jpg" alt="guide" />
data mentioned above is stored in database field. I can retrieve html fine but I can't access base_url() from database field, help me what i'm doing wrong calling php while we are already in php ??
You cannot execute PHP code inside PHP code !. I think we can do some trick to make PHP chunks executable.
At this point we need JavaScript capabilities , you have to put that column content into JavaScript variable , then output that variable to your page while loading. You can notice at that moment your PHP code converted to real output !
I hope this helping you !
you can use like this syntax.
<img src="' . base_url() . 'assets/uploads/guide-banner.jpg " alt="guide" />'
you can use like this syntax to retrieve image from database in codeignitor
<?php foreach($results_partners as $part) { ?>
<a href="main/partner" class="roller-item fancybox fancybox.ajax">
<img src="<?php echo base_url() .'cms/uploads/partners/thumb_290/'.$part->partner_image; ?>" style="width:264px; height:263px;">
</a>
<?php } ?>
assign your base_url() to a variable like
$base_url = base_url();
modify your code as shown
<p>Although the complexities, individualities and uniqueness of the human mind is beyond
imagination, let alone comprehension.</p>
<img src="{$base_url}assets/uploads/guide-banner.jpg" alt="guide" />
---^
it will solve this: change your base_url(); to the content of base_url : exp:http://localhost/blablabla;
through var_dump(base_url());
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.
I want to ask about calling the images in a folder with php
The first I've made a file to declare the image url
$url_folder_gambar = 'http://localhost/mysite/assets/img/';
I then call the php but the picture did not come out. what's wrong?
<img src="<?php echo $url_folder_gambar . people.png?>"
please help me
It looks like a syntax error. Try this:
<img src="<?php echo $url_folder_gambar;?>people.png" />
$url_folder_gambar path of the image file, some thing like http://domain/path/imagefolder/
<img src="<?php echo $url_folder_gambar;?>people.png" >
OR
<img src="<?php echo $url_folder_gambar.'people.png';?>" >
Check browser code view source using ctrl+u, check the file path, and copy the source url and pasted into the borwser, whether it is rendered or not, If not there is no file in that location.
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; ?>