PDA

View Full Version : ok, really lost now...



noxiousfix
March 2nd, 2009, 06:26 AM
alright, i posted a question in another forum about populating xml from mysql using php. i got 2 responses: " i think so" and "i don't know"...
i found this forum and i had it solved in less than 10 minutes. awesome.
now...
the reason i was looking for a script to do this:
i have a swf mp3 player that uses an xml playlist but i wanted to use it on my site with the mp3s i've upload into mysql database.
like i said, i have the xml output from php working no prob. but how do i direct it to the swf player? the player needs to be directed to an xml file in the <embed src> to get the playlist.
in short, how would i make the swf player think the php file (output xml) is really an xml file and load the playlist?
any help would be greatly appreciated,
thanks in advance.

Charleh
March 2nd, 2009, 07:11 AM
Well, you don't want to write the XML to a file, instead just 'echo' the XML to the client using the echo command.

Are you currently writing to a file? If you are just swap the code that writes to the file for a bit of code that appends all the XML to a string, then call echo $xmlString; to echo the contents to the client.

Then all you need to do is put the path to that page in the embed parameters for the swf movie, it should pick up the file from the web and assume its pure XML (as that's what the ouput will be!)

biznuge
March 2nd, 2009, 07:42 AM
as above, but you'll need to set the header type of the php output to "text/xml" or something like that...

put this in the top of your output script...



<?php header('Content-Type: text/xml'); ?>


and bob is you mothers brother...! :hugegrin:

noxiousfix
March 2nd, 2009, 07:53 AM
thanks for the reply.
i'm pretty sure that's what i'm doing. have a look:


$xml_output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$xml_output .= "<playlist version=\"0\" xmlns=\"http://xspf.org/ns/0/\"><trackList>\n";
for($x = 0 ; $x < mysql_num_rows($result) ; $x++){
$row = mysql_fetch_assoc($result);
$xml_output .= "\t<track>\n";
$xml_output .= "\t<location>../../uploads/mp3/" . $row['url'] . "</location>\n";
$xml_output .= "\t\t<image>" . $row['image_url'] . "</image>\n";
$xml_output .= "\t\t<annotation>" . $row['author'] . " - " . $row['title'] . "</annotation>\n";
$xml_output .= "\t\t<info>../../uploads/mp3/" . $row['url'] . "</info>\n";
$xml_output .= "\t</track>\n";
}
$xml_output .= "</trackList></playlist>";
echo $xml_output;


do i have this right? when i enter the url of this php (audio.php) file in my browser, it shows me the xml content as if it were an xml file. when i put audio.php in the embed src tags, i get nothing...

biznuge
March 2nd, 2009, 08:00 AM
that isn't what you're doing judging by the code man. you need to tell the browser (or flash) what mimetype to accept, whcih is what the "header" function does, so try including that at the top of your php script, before anything is output at all (important since changing the header won't work if anything has been sent to the output buffer yet) and see if that works.

good luck

noxiousfix
March 2nd, 2009, 08:00 AM
as above, but you'll need to set the header type of the php output to "text/xml" or something like that...

put this in the top of your output script...



<?php header('Content-Type: text/xml'); ?>


and bob is you mothers brother...! :hugegrin:


i have that tag at the top. although i don't have it closed like you have it above.

full code:


<?php header("Content-type: text/xml");
include_once ("../../mainfile.php");
global $xoopsDB,$xoopsUser;
$result = mysql_query('SELECT * FROM ieafd9d4c_audio WHERE uid_owner='.$xoopsUser->getVar('uid'));
$xml_output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$xml_output .= "<playlist version=\"0\" xmlns=\"http://xspf.org/ns/0/\"><trackList>\n";
for($x = 0 ; $x < mysql_num_rows($result) ; $x++){
$row = mysql_fetch_assoc($result);
$xml_output .= "\t<track>\n";
$xml_output .= "\t<location>../../uploads/mp3/" . $row['url'] . "</location>\n";
$xml_output .= "\t\t<image>" . $row['image_url'] . "</image>\n";
$xml_output .= "\t\t<annotation>" . $row['author'] . " - " . $row['title'] . "</annotation>\n";
$xml_output .= "\t\t<info>../../uploads/mp3/" . $row['url'] . "</info>\n";
$xml_output .= "\t</track>\n";
}
$xml_output .= "</trackList></playlist>";
echo $xml_output;

?>

biznuge
March 2nd, 2009, 08:17 AM
try tracing out from your flash ide and giving it a literal path to the php file to see what errors might be thrown in your swf. :S

noxiousfix
March 2nd, 2009, 08:27 AM
it says loading playlist but just sits there. the playlist never loads.

biznuge
March 2nd, 2009, 08:39 AM
got a link to the xml?

noxiousfix
March 2nd, 2009, 08:45 AM
got a link to the xml?
no. i'm running everythingon a localhost. i'm using dialup for now (save a few bucks) and getting my site finished on localhost. high speed, domain name and all that will come in a couple weeks...

Voetsjoeba
March 2nd, 2009, 09:48 AM
Biznuge is right; you need to serve the Content-type header so that Flash recognizes and accepts the HTTP response as XML. The header() call you have now takes care of that.

Another thing to keep in mind is that last time I checked Flash expects your XML file to be UTF-8 encoded, even if you specify a different encoding in the <?xml ?> tag. If you're fetching data from MySQL, then unless you've specifically set the connection encoding to UTF-8, you'll be getting ISO-8859-1 data, which does not play very well with UTF-8. You can set the connection encoding by configuration MySQL itself (which can turn out to be pretty tricky for this kind of stuff), or you can just send a SET NAMES 'utf8' query. After this query has been issued, MySQL will return all data as UTF-8.

Also, I'd advise against manually building your XML output like that. There are tons of XML subtleties you're ignoring, not the least of which is escaping illegal characters. Instead, use one of the built-in XML libraries (http://www.php.net/manual/en/book.dom.php).

Finally, make sure Flash is using the right path to call your PHP script :P

Charleh
March 2nd, 2009, 10:27 AM
Yes I may have overlooked some teeny niggling details in my answer :D

noxiousfix
March 2nd, 2009, 11:49 AM
@Voetsjoeba
flash path: check. UTF-8 encoded: uhh.....
ok, slow it down a little for me, k? all that wrapped my head into a pretzel.


unless you've specifically set the connection encoding to UTF-8, you'll be getting ISO-8859-1 data
not sure what that means. i checked mysql table columns and they're set to UTF-8. is that what you mean? or am i just "really lost now" again...?
as for the illegal characters, i removed them from the code i posted to shorten it for easier reading.


Also, I'd advise against manually building your XML output like that

i actually got that code from this forum. jubba posted it and made it sound easy.
what i dont get is when i build the output thru php the player wont read it. when i open the actaully php file in my browser, it looks exactly like an xml file. so, i copied the info from the browser, saved it as an .xml file, pointed the player to that and it worked fine.
maybe i'm in over my head here. there's just so much cool stuff i want to do and just don't have the experience to implement yet...
oh well. thanks for all the help you two.

biznuge
March 2nd, 2009, 11:59 AM
you got firefox? and the web developer plugin?

if so, hit the php page, then click "information" in the toolbar menu, and then click the "view response headers" item right at the bottom...

if you don't, then you need to get them...

get firefox (http://www.mozilla.com/en-US/), and then get the plugin (https://addons.mozilla.org/en-US/firefox/addon/60)

you might then be able to see if your localhsot is actually presenting the file as xml, or whether it's just rendering as an html page. I guess it's just possible that wamp or some other basic install of php might not have included xml support (not sure how but to assume is to make an *** out of u and me)...

Happy coding anyway man. and further good luck!

noxiousfix
March 2nd, 2009, 01:02 PM
hey thanks. i do have firefox. and now i have the plugin. sweeeet.
got this:
X-Powered-By: PHP/5.2.2Content-Type: text/xmlExpires: Thu, 19 Nov 1981 08:52:00 GMTCache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0Pragma: no-cacheConnection: Keep-AliveKeep-Alive: timeout=150000, max=10Transfer-Encoding: ChunkedDate: Mon, 02 Mar 2009 18:01:04 GMTServer: Abyss/2.5.0.0-X1-Win32 AbyssLib/2.5.0.0200 OKso it's being read as an xml file... i'll figure this out if it kills me.

noxiousfix
March 2nd, 2009, 01:19 PM
i feel like the biggest ditship. right after my last post. an idea hit me. in the WHERE clause i was getting all the info that pertained to the mp3s by uid_owner.


WHERE uid_owner='.$xoopsUser->getVar('uid')

i noticed that when i logged in under the uid=2 account (my fake account during developement), i was able to see the xml output in the browser but it wouldn't play. when i logged in under uid=1 account, i couldn't even see the output. the browser returned and error saying:



Only one top level element is allowed in an XML document. Error processing resource

not sure what that means exactly... but anyway i decided to remove getVar and just display all the mp3s in that column. wouldn't you know it... works perfectly.
it loaded all the mp3s, which isn't what i wanted but at least that's one hurdle down.
:hugegrin:

biznuge
March 2nd, 2009, 02:54 PM
Sweet. I never thought to ask if you were actually getting out of mysql what you expected.

lol!