img src not working for some cases - php

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">

Related

yii2 image not loading in html img tag but showing in browser

I am using yii2 and storing the image in root folder images. I have pointed the new domain to image folder and its working fine also in browser images are getting upload also showing in a browser but when I am trying to use them in IMG tag than it is not showing.
for ref please check below url
http://image.letspartii.com/advertisement/oJ9LFcAk2azVuGAHUrb8iyuuLqMJjUYa.png
1 - All images you want to display must be stored inside the /web folder.
2 - Use the relative path to call the img (starting inside de /web).
3 - Make sure to have the correct permission to the img folder and the file inside /web (permission and web/apache group).
Use the Url::base() method to get relative path:
<img src="<?= yii\helpers\Url::base().'/img/'.$filename; ?>"/>

Wordpress : How to set image source while creating page

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="">

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" ?>" />

Html image source from a local folder on windows options

On my html page, I make use of images which are housed in a local folder. The paths are coming directly from the database field. How can I do this? I know it wont work if the images are not in the web root directory. Can symlinks work?
For example,
The physical path to the images is c:/Images and the database field will contain the path like this, photo/image1.jpg
I will fetch the image source path from php as shown below,
<img id="image1" src="<?php echo $this->object->imagePath; ?>" class="img-polaroid">
$this->object->imagePath here will be the string concatenation of c:/Images and photo/image1.jpg. So, putting it together t will be c:/Images/photo/image1.jpg
The problem is it does not show up. I have tried this as well to test,
<img id="image1" src="file:///C:/Images/photo/image1.jpg" class="img-polaroid">
But no luck.
first let me know if putting just C:/Images/photo/image1.jpg in a browser address bar brings an image or not. If not then that's mean you are giving wrong path. Let me know so i can edit this answer. But for now this is the answer i hope.
Symlink to the folder worked like a charm.

link with same url in php

I have some thumbnail images with its larger version.I placed the thumbnail images in a page.Now for link I just gave a link
<img src="thumbnail1.jpg>
but for this I have to make different pages for showing larger one.I want to give a link to show them in a single page.means whenever I will click the thumbnail it will open the larger one in a page with the same url but with its name like
imagegallery.php?news=images/largerimage1/13.jpg
imagegallery.php?news=images/largerimage1/14.jpg
so how to do that?
Pretty basic stuff, I suggest you get to read some PHP tutorials on the internet to get some knowledge on one thing and another.
The ?news= part in your URL is a parameter that can be read by PHP. This type is known as $_GET. To get this part you would need $_GET['news'] so if we'd use your first link and place this inside a script: echo $_GET['news']; the page would say images/largerimages1/13.jpg.
In order to get the image loaded on your website we need some simple steps, I'm changing the news parameter into image, that suits better for your script since it ain't news items:
<?php
// Define the path (used to see if an image exists)
$path = 'your/absolute/path/to/public_html/'; # or wwwroot or www folder
// First check if the parameter is not empty
if($_GET['image'] != "") {
// Then check if the file is valid
if(file_exists($path . $_GET['image'])) {
// If an image exists then display image
echo '<img src="'. $_GET['image'] . '" />;
}
}
?>
Below this script you can put all your thumbnails the way you want. Ofcourse, also for these thumbnails there are some automated options. But I strongly suggest you get a good look at the script above and some beginner PHP tutorials so you completely understand the example given. This still isn't the best method, but it's kicking you in the right direction.
if your imagegallery.php is in root of your domain, you can just add slash as a first char to links like this:
<img src="thumbnail1.jpg>
else you will have to write some php function which it returns BaseUrl of your web. Then it should looks like this:
<img src="thumbnail1.jpg>
maybe you can something like this,
Techincally, there is no thumbnail image, just a stretch version of the regular image
I don't understand which part you don't know how to do:
- the link part?
it should look like
<img src="thumbnail1.jpg>
- or the PHP part (the file called imagegallery.php)?

Categories