Graxeon Posted November 28, 2009 Share Posted November 28, 2009 I have 2 files. The first is a PHP generated XML file that's dependent by 2 inputs. The second is a PHP file that grabs the content of the XML file. So I have this: site.com/xml.php?p=RAINBOW&z=SOCCER <playlist version="1"> <trackList> <track> <title>SOCCER - RAINBOW</title> <location>http://www.site.com/soccer-rainbow.m4v</location> <duration>23:27</duration> <info>http://www.site.com/info.php?video=RAINBOW&title=SOCCER</info> <meta rel="type">m4v</meta> <image>images.php?title=SOCCER&video=RAINBOW</image> </track> <track> <title>SOCCER</title> <location/> <meta rel="type"/> </track> </trackList> </playlist> I want to grab the contents of the "location" tags. So, I have this now: media.php?p=RAINBOW&z=SOCCER $title = $_GET['p']; $video = $_GET['z']; $myXML = 'www.site.com/xml.php?p=' .$title. '&z='.$video; $sxml = simplexml_load_string($myXML); list($node) = $sxml->xpath('/playlist/trackList/track/location'); header("Location: $node"); But I get the error "Fatal error: Call to a member function xpath() on a non-object on line 9". What variables did I mess up? Can someone help me fix it, please? Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/ Share on other sites More sharing options...
Alex Posted November 28, 2009 Share Posted November 28, 2009 use simplexml_load_file, not simplexml_load_string(). Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967101 Share on other sites More sharing options...
Graxeon Posted November 28, 2009 Author Share Posted November 28, 2009 I just get a blank page with that change Edit: Even when I make $myXML = 'site.com/xml.xml' where "xml.xml" is the full XML file, I get this error: Fatal error: Call to a member function xpath() on a non-object on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967107 Share on other sites More sharing options...
Alex Posted November 28, 2009 Share Posted November 28, 2009 You should include http:// in the URL. Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967110 Share on other sites More sharing options...
Graxeon Posted November 28, 2009 Author Share Posted November 28, 2009 The error is with the full link in place. So it's not a URL problem. Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967111 Share on other sites More sharing options...
Alex Posted November 28, 2009 Share Posted November 28, 2009 Is this what you're doing?: $myXML = 'http://www.site.com/xml.php?p=' .$title. '&z='.$video; $sxml = simplexml_load_file($myXML); Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967114 Share on other sites More sharing options...
Graxeon Posted November 28, 2009 Author Share Posted November 28, 2009 Yes, I am. However...this gives a blank page: <?php $title = $_GET['p']; $video = $_GET['z']; $myXML = 'http://www.site.com/media.php?p=' .$title. '&z='.$video; $sxml = simplexml_load_file($myXML); list($node) = $sxml->xpath('/playlist/trackList/track/location'); header("Location: $node"); ?> So, I wanted to test to see if I'm even linking correctly and did this: <?php $myXML = 'http://www.site.com/xml.xml'; $sxml = simplexml_load_file($myXML); list($node) = $sxml->xpath('/playlist/trackList/track/location'); header("Location: $node"); ?> And that gave me the fatal error. So, even when I link it directly to an already generated XML file, I get an error. Idk if that helps at all, though. THIS, however, works: <?php $myXML ='<playlist version="1"> <trackList> <track> <title>SOCCER - RAINBOW</title> <location>http://www.site.com/soccer-rainbow.m4v</location> <duration>23:27</duration> <info>http://www.site.com/info.php?video=RAINBOW&title=SOCCER</info> <meta rel="type">m4v</meta> <image>images.php?title=SOCCER&video=RAINBOW</image> </track> <track> <title>SOCCER</title> <location/> <meta rel="type"/> </track> </trackList> </playlist>'; $sxml = simplexml_load_string($myXML); list($node) = $sxml->xpath('/playlist/trackList/track/location'); header("Location: $node"); ?> Why doesn't it work when I don't put the XML file in the $myXML var and just link to it? Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967116 Share on other sites More sharing options...
Alex Posted November 28, 2009 Share Posted November 28, 2009 Looks like you can't grab remote files (fopen_wrappers is probably disabled). You might want to try cURL to obtain the remote xml file. Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967121 Share on other sites More sharing options...
Graxeon Posted November 28, 2009 Author Share Posted November 28, 2009 Huh? Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967134 Share on other sites More sharing options...
Alex Posted November 28, 2009 Share Posted November 28, 2009 Grab the remote xml file using cURL as a string and then pass it into simplexml_load_string(). Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967139 Share on other sites More sharing options...
Graxeon Posted November 29, 2009 Author Share Posted November 29, 2009 I don't really understand cURL. I'm not too great with PHP. Can you help me with it, please? Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967216 Share on other sites More sharing options...
Graxeon Posted November 29, 2009 Author Share Posted November 29, 2009 Are you there Alex? Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967272 Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 Here's an example: $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'WEBSITE URL HERE'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $myXML = curl_exec ($curl); curl_close($curl); // .. The rest of your code Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967275 Share on other sites More sharing options...
Graxeon Posted November 29, 2009 Author Share Posted November 29, 2009 Like this? Cause this gives a blank page: <?php $title = $_GET['p']; $video = $_GET['z']; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://www.site.com/media.php?p=' .$title. '&z='.$video); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $myXML = curl_exec ($curl); curl_close($curl); $sxml = simplexml_load_file($myXML); list($node) = $sxml->xpath('/playlist/trackList/track/location'); header("Location: $node"); ?> Or which code are you talking about? Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967284 Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 Yes, except for use simplexml_load_string() inside of simplexml_load_file() now that you should have the contents of the XML file in $myXML. Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967285 Share on other sites More sharing options...
Graxeon Posted November 29, 2009 Author Share Posted November 29, 2009 Nope, still get a blank page. Is there a simpler way of getting the content within the "location" tags in the XML file?: http://www.site.com/xml.php?p=RAINBOW&z=SOCCER <playlist version="1"> <trackList> <track> <title>SOCCER - RAINBOW</title> <location>http://www.site.com/soccer-rainbow.m4v</location> <duration>23:27</duration> <info>http://www.site.com/info.php?video=RAINBOW&title=SOCCER</info> <meta rel="type">m4v</meta> <image>images.php?title=SOCCER&video=RAINBOW</image> </track> <track> <title>SOCCER</title> <location/> <meta rel="type"/> </track> </trackList> </playlist> Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967291 Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 Can you post the actual link to the website so I can try this myself? Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967292 Share on other sites More sharing options...
Graxeon Posted November 29, 2009 Author Share Posted November 29, 2009 I can't give you the actual website without confirmation from the owner. However, that XML file is the same exact copy. How it's generated is complex, however the final output is that. So, the URL that I'm giving is the basic setup that leads to that XML content. So it's the same thing. I can upload a plain XML file with that same content for you, but the "p=" and "z=" won't be part of the execution (though ofc that can be added later). Here's a test XML file with the same thing: http://fr33.ulmb.com/gr/xml.xml Sorry for taking up your time, I just really need to finish this. EDIT: I have to head out to work. If you want me to answer anything just leave a post, I'll be back in about 10 hours. Again, thatnks for your time! Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967302 Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 Uploading the xml file to a remote local myself and testing this it worked fine: $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://website.com/somefile.xml'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $myXML = curl_exec ($curl); curl_close($curl); $sxml = simplexml_load_string($myXML); list($node) = $sxml->xpath('/playlist/trackList/track/location'); header("Location: $node"); I suggest you put error_reporting(E_ALL); at the top of your page and post back any errors. Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967307 Share on other sites More sharing options...
Graxeon Posted November 29, 2009 Author Share Posted November 29, 2009 Tried that, got this: Fatal error: Call to a member function xpath() on a non-object on line 10 Did the same thing as you (uploaded it remotely with NO "p=" and "z=" inputs). How is it a non-object? Alright, I'm off before I'm late. Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967316 Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 You're obviously having a problem getting the contents of the file. Check to see if $myXML contains the contents of the file you expect it does. Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967320 Share on other sites More sharing options...
Graxeon Posted November 29, 2009 Author Share Posted November 29, 2009 Here are my files: http://fr33.ulmb.com/gr/grzid6.php <?php $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://fr33.ulmb.com/gr/xml.xml'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $myXML = curl_exec ($curl); curl_close($curl); $sxml = simplexml_load_string($myXML); list($node) = $sxml->xpath('/playlist/trackList/track/location'); header("Location: $node"); ?> http://fr33.ulmb.com/gr/xml.xml <playlist version="1"> <trackList> <track> <title>SOCCER - RAINBOW</title> <location>http://www.site.com/soccer-rainbow.m4v</location> <duration>23:27</duration> <info>http://www.site.com/info.php?video=RAINBOW&title=SOCCER</info> <meta rel="type">m4v</meta> <image>images.php?title=SOCCER&video=RAINBOW</image> </track> <track> <title>SOCCER</title> <location/> <meta rel="type"/> </track> </trackList> </playlist> Did I mess something up? Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967330 Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 That won't work because http://fr33.ulmb.com/gr/xml.xml prompts you for a 60 second wait before downloading the file, so you'll be getting the contents of that page, not the actual xml file. Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967331 Share on other sites More sharing options...
Graxeon Posted November 29, 2009 Author Share Posted November 29, 2009 Is there a way around that? But either way, it's the same content, isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967337 Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 No, it's not the same content, completely different. If you try to get the contents of that page you get: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> <title>Download xml.xml</title> <script type="text/javascript" language="JavaScript"><!-- function docountdown(){ s_div = document.getElementById("dldiv"); count = count - 1; if (count > 0){ s_div.innerHTML = "Your request to download xml.xml is being processed.<"+"p>Please Wait... ("+count+" seconds remaining)<"+"/p>"; setTimeout("docountdown();", 1000); } else { s_div.innerHTML = "Your file is ready for download.<"+"p><"+"a href=\"/gr/xml.xml?\">Click here to Download File<"+"/a><"+"/p>"; } } var count = 60; window.onload = docountdown; --></script> </head> <body> <div align="center"> <script type="text/javascript"><!-- google_ad_client = "pub-2927823587298693"; google_alternate_color = "FFFFFF"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_channel =""; google_color_border = "336699"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_url = "008000"; google_color_text = "000000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <br /><br /> <table border="0" width="500"> <tr> <td> <fieldset style="padding: 2"> <legend>Download xml.xml</legend> <br /> <div id="dldiv"> Your request to download xml.xml is being processed.<p>Please Wait...</p> </div> <br /> </fieldset> <p> </td> </tr> </table> <script type="text/javascript"><!-- google_ad_client = "pub-2927823587298693"; google_alternate_color = "FFFFFF"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_channel =""; google_color_border = "336699"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_url = "008000"; google_color_text = "000000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.