Image cannot be loaded. Make sure the path is correct and the image exists
-
22-06-2021 - |
Вопрос
On my page I have a YouTube video's thumbnail as image, and I want to play the video using prettyPhoto after the user clicks on the image. How can I accomplish that?
Here's my code for the image:
<div class="video" id="videoPlaceHolder" style="position:relative;">
<a rel="prettyPhotos" href="https://www.youtube.com/embed/<?php getFirstFeatureVideoURL(); ?>">
<img style="background:url(<?php getFirstFeatureVideoThumbnail() ?>); background-repeat:no-repeat; background-size:cover; -moz-background-size: cover;" src="/images/ytIndex_overlay.png" onClick="addPlayer();" />
</a>
</div>
The php function getFirstFeatureVideoURL
grabs and returns the first video's "correct" URL (I have checked it separately and the video plays w/o any problem). The other function called getFirstFeatureVideoThumbnail
returns the video's thumbnail. I have all the plugins ready for the prettyPhoto
, and so far it's working for all the images perfectly. However, when I try to play this video by clicking on the image, it gives me the error:
Image cannot be loaded. Make sure the path is correct and the image exists
Why am I getting this error?
Решение 3
Okay, so I ended up generating the < a > and < img > tags inside my PHP function like below and that fixed my problem....
function getFeatureVideo()
{
$xml = simplexml_load_file('https://gdata.youtube.com/feeds/api/playlists/A4F160EDF82713A2?v=2');
.
.
.
.
$media = $entry->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
$attrs = $media->group->thumbnail[1]->attributes();
$thumbnail = $attrs['url'];
$result .='<a rel="prettyVideos" href="'.$watch.'">
<img style="background:url('.$thumbnail.'); background-repeat:no-repeat; background-size:cover; -moz-background-size: cover;" src="/images/ytIndex_overlay.png" onClick="addPlayer();" />
</a> ';
echo $result;
}
Другие советы
It expects the href
to be a URL. You can't embed PHP code in a URL like that.
What is the thumbnail version you are trying to get. I guess you try to retrieve Standard Definition Thumbnail or Maximum Resolution Thumbnail. Both of them does not exist for this video id: Id_kGL3M5Cg
Use this tool to check of it exist or not: YouTube video info generator
I got the result, Standard Definition Thumbnail is not available for this video. Maximum Resolution Thumbnail is not available for this video.
You can check if image exist or not using get_headers
. Check the thumbnail section of the code in this tutorial: How to get YouTube Video Info with PHP