Wordpress : How to set image source while creating page - php

how can i set image url in page ?
In image you can see I have tried by three ways but it not work.
Images are located under image folder of active theme.

You have three image tags all pointing to different urls of which two appear malformed.
The middle image tag in your screenshot seems the most accurate but you may want to add a semicolon after the right paranthesis.
If all three files are supposed to refer to the same image, then replace the first and last image tags with the middle one.
Then if it still doesnt work then replace bloginfo('template_directory') with the actual location to the images relative to document root on the server but put the value in quotes. For example, if your images are in the subfolder images in folder imageset on your site, then you could use
"http://www.whatever.com/imageset/images" or "/imageset/images".
which results in the code:
<img src="<?php echo "/imageset/images"; ?>/images/banner1.jpg" alt="">
or even better:
<img src="/imageset/images/images/banner1.jpg" alt="">

Try as follows <img src="../images/banner1.jpg" alt="">

Related

img src not working for some cases

what i'm basically doing is to save some images within some directory of my localhost, the problem is when i try to show them. But here's the thing:
In my directory i have two exact images, named differently, one is named based on a unique name generated, and the other is named as it would normally be named.
For example:
Image No. 1 is called: o9z2z2f545faf1d1.jpg
Image No. 2 is called: testImage.jpg
When i want to show them i normally do it this way
<img src = "<?php echo $prize['Prize']['imageUrl']; ?>">
If i inspect the element i get "http://localhost:8080/admin/img/prizes/o9z2z2f545faf1d1.jpg"
If i do it this way it doesnt show anything.
But if i do this
<img src = "../../img/prizes/testImage.jpg">
And then if i inspect the element it gives: "http://localhost:8080/admin/img/prizes/testImage.jpg"
I check on the folder where the images are saved, and they look fine. its when i get to call them by the unique name that fails
How can i solve this?
Thank you very much!!
Try use the base tag in the head tag or absolute path of image.
<img src = "http://localhost:8080/admin/img/prizes/testImage.jpg">

Images are not appeared in pages other than default URL

All the Images of the website doesn't appear.
If I access the default url, specified in config file, under the base_url, all the images have shown.
But when I access this url (127.0.0.1/dcm/Controller/Index), not even a single image is retrieved.
I think it's a path problem, but I can't figure it out properly.
Here's my root folder structure (I'll try to make it understandable):
css
dcmapp -> Here I have my views
dcmsys
htmlconstants -> Here are my header and footer, common in all pages
Images -> Here are all the website images
Scripts
For example, in my header.php in htmlconstants folder, I have this code, for example:
<img src="<?php base_url() ?>Images/fbic.png">
<img src="Images/phone.png">
<img src="Images/email.png">
As you can see in code, I'm trying to use a base_url function to see if I can get the full path till the image, with no success.
In my Views, the same thing.
instead of
<img src="<?php base_url() ?>Images/fbic.png">
try this:
<img src="<?php echo base_url(); ?>Images/fbic.png"></img>

Image is not displaying in Yii

I have img tag in my view file (yii frame work). and image is displayed in most of the times. some times the images are not displaying. when I inspect the element, then it shows the img path as src="hhhh://localhost/projects/aaa/images/sample-img-left.png". here for http://, hhhh:// comes. Iam not getting any idea with how this hhhh comes. help me please
You can call Yii::app()->request->baseUrl to get the location where your project resides, then append it with the image path.
For Eg.
<img src="<?php echo Yii::app()->request->baseUrl."/images/sample-img-left.png" ?>" />

How to to access images on main domain from subdomain

I have a main domain that users can upload images to which are then viewed in a slider so multiple images (sometimes up to 50) are loaded by the page on loading. I am trying to access the same images on a subdomain but it isn't working very well.
If I use
<img src="<? echo 'http://www.mysite.co.uk/'.$row['imageLocation']; ?>">
the images load but it is very slow
If I use
<img src="<? echo '/home/myname/public_html/mysite.co.uk/'.$row['imageLocation']; ?>">
the images aren't displayed despite the path being correct. If I use the same path for getting the images sizes (getimagesize) it returns the correct results so I'm sure the path is correct.
The images arent shown because you echo the path to the user first, but not the file itself and then the users browser loads them asynchronously. He cannot access any parent directory from mysite.co.uk only child directories.
The PHP can load them because it runs on the server itself before it is returning anything.
What you could do is using the readfile() function from PHP in an extra PHP file like getimages.php or just use the first solution, which cannot be improved in speed except you will change the image sizes, which might be your main problem here.
If you want to directly echo image file content, use this.
<img src="data:image/jpeg;base64,<?php echo base64_encode('/home/myname/public_html/mysite.co.uk/'.$row['imageLocation']); ?>" />

How to retrieve and show images from another drive using src attribute in <img> tag?

<img src="d:/Tulips.jpg" >
</img>
<img src="file:///d:Tulips.jpg">
How to retrieve and show images from another drive using src attribute in <img> tag?
If the image is in the same folder it works but when the source of the image is on another drive it's not working.
jpgYou can't put your file system path in the src unless you open it from your desktop or your computer. You can try to pass the file as base64 encoded strings. I'm showing how to do it in PHP because you tagged this question with PHP
$image = file_get_contents('d:/Tulips.jpg');
$image_codes = base64_encode($image);
And in your html put it like this.
<image src="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" />
Try
<img src="file:///d:/Tulips.jpg">
You were missing a slash after your drive lettter.
The reason is you are doing the inevitable.
HTML markups cannot read data from the local disk drives, you need to put them in a folder or access it from the same directory for this to work.
Since, when you publish your website images are to be accessed from the folders of your webserver, accessing from a hard-drive directly (not possible via HTML though) puts you under potential risks.

Categories