how calling the images in a folder with php - php

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.

Related

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.

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.

I have an error in my PHP code set up to view my images

<?php
$con=mysql_connect ("xxx","xxx","xxx");
mysql_select_db("dbhappps",$con);
#$sql="select * from tbl_image where id='4' and status='0'";
#$query=mysql_query($sql);
while(#$row=mysql_fetch_array($query))
{
#$image=$row ['photo'];
echo $image
?>
<img src="/image/<?php echo $image; ?>" width="320" height="480">
<?php
}
?>
The echo $image is giving me the correct file name so I am either not referencing the /image (the image folder is in my root directory) folder correctly or could it be a browser issue? I am testing it in google chrome. any tips would be great.
View source in the browser and see if there are any unneeded spaces etc. Also just right click on the image and copy image url and paste in browser to check if the image really does exist. I think its a path issue more than a browser issue.
try this
<img src="//yourwebsite.com/image/<?php echo $image; ?>" width="320" height="480">
Replace yourwebsite with your website name. or localhost/test etc.
Also check that you are getting .jpg .gif. jpeg extension in the last. other wise use this
<img src="//yourwebsite.com/image/<?php echo $image; ?>.jpg" width="320" height="480">

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; ?>

How to add images to a wordpress theme when working on MAMP?

I am new to MAMP and I am developing a theme I designed. However I can't seem to get the images to render. I am using a clear theme I got from starkerstheme.com
When adding an image directly to the code I used:
<img src="<?= $theme ?>/images/logo.png"/>
But the image is not showing up, also I tried to add it to the media library and it's still not rendering.
This works for me:
<img src="<?php echo get_bloginfo('template_url') ?>/images/logo.png"/>
See get bloginfo() function for more info.
You can use the following code to add an image. This works for me:
<img src="<?php echo get_template_directory_uri(); ?>/images/filename.png">
<?php echo get_template_directory_uri(); ?>
as suggested gets the PARENT theme, which is OK but if you've developed a child theme (as recommended by WordPress people) you need:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/Logo.png">
Just go to your dashboard and upload your picture in the media section, then select it you'll see the image options .. then copy it's url
<img src="your/copied/url"/>
This aslo works for me in localhost
You might need to do the full <img src="<?php echo $theme; ?>/images/logo.png"/>
Update I didn't read your question closely enough. If you're using the media library for the image, you'll need to specify the actual path to the image. You can figure this out from within the media library, but it's probably site_url/wp-content/uploads/2012/01/filename.jpg
In short, if you uploaded it in media, it wouldn't actually be in your theme.
<?php bloginfo('template_directory'); ?>/
use for internal root folder in images to place on theme on wordpress.
The forward slash is needed for the image to show
Remove the = after <?
<img src="<? $theme ?>/images/logo.png"/>
in fact, I'd probably do something like this:
<img src= <?php $theme ?> . "/images/logo.png"/>
on 2021...
Just name the image as screenshot.png [ recommended image size (currently) is 1200px wide by 900px ] and put it on theme's top-level directory (where the style.css file is )
and that's all you need to do.

Categories