Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:17:06+00:00 2026-06-09T06:17:06+00:00

I have had lots of help with creating a PHP script that basically grabs

  • 0

I have had lots of help with creating a PHP script that basically grabs the latest titles and thumbnails of videos from a YouTube playlist. This used to work, but somehow it has stopped working. Could anybody help?

The php script is running at http://new.fearofmobs.com/playlist.php, i’ve switched on error reporting. The script is mean’t to return thumbnails from a YouTube playlist and cache them hourly. The code

<?php error_reporting(E_ALL ^ E_NOTICE); ini_set('display_errors', 1);?>

<?php
$cachefile = 'videobrowser.txt';
$cache_timer = 3600 + @filemtime($cachefile);// files timestamp + 3600 seconds
if (file_exists($cachefile) && time() < $cache_timer ) {
}
else {
    $data = file_get_contents("http://gdata.youtube.com/feeds/api/playlists/C82EBDAC0429B6A2?orderby=published&max-results=12");
    $fh = fopen($cachefile, 'w') or die("can't open file");
    fwrite($fh, $data);
    fclose($fh);
}

$thumbnail ='';
$data = simplexml_load_file($cachefile);
$xml = simplexml_load_string($data);
foreach($xml->entry as $playlist){
    $media = $playlist->children('http://search.yahoo.com/mrss/');
    $attrs = $media->group->thumbnail[1]->attributes();
    $thumb = $attrs['url'];
    $attrs = $media->group->player->attributes();
    $video = $attrs['url'];
    $title = substr( $media->group->title, 21);
    $url = $video;
    parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
    $vid_Id = $my_array_of_vars['v'];

    ###################NEW CODE
    $toggle = 'hotlink';// replace 'hotlink' with 'null' to save images locally
    if ($toggle == 'hotlink'){
        $image_ID = $thumb;  // hotlink images from YouTube
    }
    else{
        ///////////////////////////////// Save Images To Local Webserver
        ///////////////////////////////// just in case  Youtube objects to hotlinking

        $image_ID = $vid_Id.".jpg"; /// or use sub folder for neatness ->  "images_folder/".$vid_Id.".jpg"
        $image_saved = @filemtime($image_ID);// @ is used to suppress the error caused by the image not having been seen before
        if (!$image_saved){/// if you can't find it on local server go fetch it and save to the sites server
            file_put_contents($image_ID, file_get_contents($thumb));

            //// you can delete the line below
            echo ' fecthed image >> '.$image_ID."<br>" ;
            //// you can delete the line above

        }//// close if image saved
    }        ##################### END NEW CODE

    $thumbnail .= '<div style="float:left; cursor:pointer;">
    <p class="crop"><a class="videobox various iframe" href="http://www.youtube.com/embed/' . $vid_Id . '?autoplay=1&amp;hd=1" onclick=swapper('. $vid_Id .')><img src="' .$image_ID  . '" title="' . $title . '" width="74" height="56"/></a></p></div>';
}
?>

<?php echo $thumbnail; ?>

The errors

Warning: simplexml_load_file(): videobrowser.txt:1: parser error : Document is empty in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file():  in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file(): ^ in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file(): videobrowser.txt:1: parser error : Start tag expected, '<' not found in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file():  in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file(): ^ in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: Invalid argument supplied for foreach() in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 18

If anybody needs any further information please do let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:17:09+00:00Added an answer on June 9, 2026 at 6:17 am

    As far as I can tell, you are not entering the else clause that populated videobrowser.txt:

    if (file_exists($cachefile) && time() < $cache_timer ) {
        // you are going here
    }
    else {
        // but you should be going here
        $data = file_get_contents("http://gdata.youtube.com/feeds/api/playlists/C82EBDAC0429B6A2?orderby=published&max-results=12");
        $fh = fopen($cachefile, 'w') or die("can't open file");
        fwrite($fh, $data);
        fclose($fh);
    }
    

    I’m guessing that at some point videobrowser.txt was created with no content (a completely empty file). This means that you are not re-populating the file, and are expecting it to be filled.

    Check and see if videobrowser.txt exists, and if it does, delete it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have had several situations when i would like to do that. This could
I had an issue with DBMS_SCHEDULER in oracle.I have an external programme(a perl script
I have had lots of trouble with deploying my rails 3.0.10 application to Ubuntu
I have got lots of ideas from google and stackoverflow- but none of those
I have never had a problem getting Facebook to show thumbnails for shared links
I have had an online archive service for over a year now. Unfortunately, I
I have had to compile my app for the 4.0 sdk to run on
I have had a persistent problem with Visual Studio 2010 and any framework version
I have had this problem crop up a few times and I can't figure
I have had a look all over, but it doesn't seem as though my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.