Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/183240-load-file-in-php/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967116
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967284
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967291
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967302
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967307
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967330
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/183240-load-file-in-php/#findComment-967342
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.