Log in

View Full Version : How to code in XML files Using PHP



archanarj9
02-15-2012, 08:59 AM
Here is the code in my XML files....
<code>
<image img="images/image1.jpg" customtitle="Camomile" />
<image img="images/image2.jpg" customtitle="Bells" />
<image img="images/image3.jpg" customtitle="Market" />
<code>

Which is working fine.
I want this images to be dynamic i.e shld be fetched from database. So my ques is How to add php code in XML files or Is there any other way i can do this.Pls Guys Help me OUT.Its Urgent.

jscheuer1
02-15-2012, 03:38 PM
That's not valid xml. At the very least, that second <code> tag should be a closing tag:


</code>

How about providing a link to the xml file?

And you can't have PHP code in an xml file unless the host is directed to parse xml as PHP, and that might create other problems. It's worth a try though.

But the first thing I would try is using a PHP page with an xml header instead of the xml file. I'm not up on fetching data from a database, but you can probably look that part up if you don't already know it. So let's say your xml file is called images.xml. You could make up a PHP file - images.php:


<?php
header ("content-type: text/xml");
echo '<code>
<image img="images/image1.jpg" customtitle="Camomile" />
<image img="images/image2.jpg" customtitle="Bells" />
<image img="images/image3.jpg" customtitle="Market" />
</code>';
?>

put it's filename where you had the filename for images.xml in your Flash code (it's probably either in the flashvars or in a config file), and if that works, you're basically home free because that means you can do something like:


<?php
header ("content-type: text/xml");
echo "<code>\n";
// do your fetching from the database here as a loop or whatever to produce the xml image tags
echo "</code>\n";
?>

If that doesn't work, and as I say, I'm not up on fetching data from a database. But if you have that part figured out, you could always use:

file_put_contents (http://www.php.net/manual/en/function.file-put-contents.php)

to create the xml file.

Note: The file_put_contents command requires PHP 5+, But if you have less than that you can use fopen(), fwrite() and fclose() as explained and linked to on the page for file_put_contents. And regardless of which method you use, the server must have those enabled. Some do not. Of those that don't, some can be enabled by you or by a request in email to the host, with others it's just policy and they will not lift the restriction without upgrading the account. Some won't even allow an upgrade. For the most part there is a way though and many, if not most do have these enabled.

The file would need to be created before it's required by the Flash object.

If you want more help, please supply a link to the page with the Flash object on it.

archanarj9
02-18-2012, 07:15 AM
If you want more help, please supply a link to the page with the Flash object on it.

Thank John But My problem is not solved yet as i created PHP replacing XML file.then also my flash not working. Here is My XML File Code :-


<?xml version="1.0" encoding="iso-8859-1"?>


<slideshow displayTime="2"
transitionSpeed=".7"
transitionType="Fade"
motionType="None"
motionEasing="easeInOut"
randomize="false"
slideshowWidth="400"
slideshowHeight="220"
slideshowX="center"
slideshowY="0"
bgColor="FFFFFF"
bgOpacity="100"
useHtml="true"
showHideCaption="false"
captionBg="000000"
captionBgOpacity="0"
captionTextSize="11"
captionTextColor="FFFFFF"
captionBold="false"
captionPadding="7"
showNav="false"
autoHideNav="false"
navHiddenOpacity="40"
navX="335"
navY="193"
btnColor="FFFFFF"
btnHoverColor="FFCC00"
btnShadowOpacity="85"
btnGradientOpacity="20"
btnScale="120"
btnSpace="7"
navBgColor="333333"
navBgAlpha="0"
navCornerRadius="0"
navBorderWidth="1"
navBorderColor="FFFFFF"
navBorderAlpha="0"
navPadding="8"
tooltipSize="8"
tooltipColor="000000"
tooltipBold="true"
tooltipFill="FFFFFF"
tooltipStrokeColor="000000"
tooltipFillAlpha="80"
tooltipStroke="0"
tooltipStrokeAlpha="0"
tooltipCornerRadius="8"
loaderWidth="200"
loaderHeight="1"
loaderColor="FF0000"
loaderOpacity="100"

attachCaptionToImage="true"
cropImages="false"
slideshowMargin="0"
showMusicButton="false"
music="images/music.mp3"
musicVolume="50"
musicMuted="false"
musicLoop="true"
watermark=""
watermarkX="625"
watermarkY="30"
watermarkOpacity="100"
watermarkLink=""
watermarkLinkTarget="_blank"
captionsY="bottom"
>

<image img="images/image1.jpg" customtitle="Camomile"/>
<image img="images/image2.jpg" customtitle="Bells"/>
<image img="images/image3.jpg" customtitle="Market" />
<image img="images/image4.jpg" customtitle="Market" />
<image img="images/image5.jpg" customtitle="Market" />
<image img="images/image6.jpg" customtitle="Market" />
<image img="images/image7.jpg" customtitle="Market" />

</slideshow>

Pls Help me. Its Urgent. Need Help Asap

jscheuer1
02-18-2012, 07:39 AM
We can go about this piecemeal. But for me to find a solution, I really need to see it.

Please post a link to the page on your site that contains the problematic code so we can check it out.

Preferably to a page with the Flash on it, working and using the hard coded xml file.

archanarj9
02-18-2012, 08:26 AM
This is the code i have done in slideshow.php

<?php header("Content-type: text/xml");
'<slideshow displayTime="2"
transitionSpeed=".7"
transitionType="Fade"
motionType="None"
motionEasing="easeInOut"
randomize="false"
slideshowWidth="400"
slideshowHeight="220"
slideshowX="center"
slideshowY="0"
bgColor="FFFFFF"
bgOpacity="100"
useHtml="true"
showHideCaption="false"
captionBg="000000"
captionBgOpacity="0"
captionTextSize="11"
captionTextColor="FFFFFF"
captionBold="false"
captionPadding="7"
showNav="false"
autoHideNav="false"
navHiddenOpacity="40"
navX="335"
navY="193"
btnColor="FFFFFF"
btnHoverColor="FFCC00"
btnShadowOpacity="85"
btnGradientOpacity="20"
btnScale="120"
btnSpace="7"
navBgColor="333333"
navBgAlpha="0"
navCornerRadius="0"
navBorderWidth="1"
navBorderColor="FFFFFF"
navBorderAlpha="0"
navPadding="8"
tooltipSize="8"
tooltipColor="000000"
tooltipBold="true"
tooltipFill="FFFFFF"
tooltipStrokeColor="000000"
tooltipFillAlpha="80"
tooltipStroke="0"
tooltipStrokeAlpha="0"
tooltipCornerRadius="8"
loaderWidth="200"
loaderHeight="1"
loaderColor="FF0000"
loaderOpacity="100"
attachCaptionToImage="true"
cropImages="false"
slideshowMargin="0"
showMusicButton="false"
music="images/music.mp3"
musicVolume="50"
musicMuted="false"
musicLoop="true"
watermark=""
watermarkX="625"
watermarkY="30"
watermarkOpacity="100"
watermarkLink=""
watermarkLinkTarget="_blank"
captionsY="bottom"
>
<image img="images/image1.jpg" customtitle="Camomile" />
<image img="images/image2.jpg" customtitle="Bells" />
<image img="images/image3.jpg" customtitle="Market" />
<image img="images/image4.jpg" customtitle="Market" />
<image img="images/image5.jpg" customtitle="Market" />
<image img="images/image6.jpg" customtitle="Market" />
<image img="images/image7.jpg" customtitle="Market" />

</slideshow>';
?>

On Running this page i m getting Following Error:

"This page contains the following errors:
error on line 2 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error. "

jscheuer1
02-18-2012, 08:47 AM
That's never going to work. Try (slideshow.php):


<?php
header ("content-type: application/xml");
echo '<?xml version="1.0" encoding="iso-8859-1"?>


<slideshow displayTime="2"
transitionSpeed=".7"
transitionType="Fade"
motionType="None"
motionEasing="easeInOut"
randomize="false"
slideshowWidth="400"
slideshowHeight="220"
slideshowX="center"
slideshowY="0"
bgColor="FFFFFF"
bgOpacity="100"
useHtml="true"
showHideCaption="false"
captionBg="000000"
captionBgOpacity="0"
captionTextSize="11"
captionTextColor="FFFFFF"
captionBold="false"
captionPadding="7"
showNav="false"
autoHideNav="false"
navHiddenOpacity="40"
navX="335"
navY="193"
btnColor="FFFFFF"
btnHoverColor="FFCC00"
btnShadowOpacity="85"
btnGradientOpacity="20"
btnScale="120"
btnSpace="7"
navBgColor="333333"
navBgAlpha="0"
navCornerRadius="0"
navBorderWidth="1"
navBorderColor="FFFFFF"
navBorderAlpha="0"
navPadding="8"
tooltipSize="8"
tooltipColor="000000"
tooltipBold="true"
tooltipFill="FFFFFF"
tooltipStrokeColor="000000"
tooltipFillAlpha="80"
tooltipStroke="0"
tooltipStrokeAlpha="0"
tooltipCornerRadius="8"
loaderWidth="200"
loaderHeight="1"
loaderColor="FF0000"
loaderOpacity="100"

attachCaptionToImage="true"
cropImages="false"
slideshowMargin="0"
showMusicButton="false"
music="images/music.mp3"
musicVolume="50"
musicMuted="false"
musicLoop="true"
watermark=""
watermarkX="625"
watermarkY="30"
watermarkOpacity="100"
watermarkLink=""
watermarkLinkTarget="_blank"
captionsY="bottom"
>

<image img="images/image1.jpg" customtitle="Camomile"/>
<image img="images/image2.jpg" customtitle="Bells"/>
<image img="images/image3.jpg" customtitle="Market" />
<image img="images/image4.jpg" customtitle="Market" />
<image img="images/image5.jpg" customtitle="Market" />
<image img="images/image6.jpg" customtitle="Market" />
<image img="images/image7.jpg" customtitle="Market" />

</slideshow>';
?>

archanarj9
02-18-2012, 09:49 AM
Thank You So So much U have solved my Problem. But Pls Let me Know that its not getting loaded in Flash File. i.e Flash not working.Pls Pls Let me Know how to do that...... Thank's So much in Advance.

jscheuer1
02-18-2012, 10:19 AM
I still need a link to the page.

I did do some supplemental searching on this one and found:

http://www.flashnifties.com/support/viewtopic.php?id=63

It looks like the same xml file, so I'm assuming it's the same Flash slideshow.

If so, we can know that a PHP file will work.

I also mention this because - perhaps in that forum you can get more help.

I downloaded the free version and it works with the slideshow.php file:


<div id="flashcontent">
<a href="iphone/index.php" class="iphoneBtn">Launch iPhone Slideshow</a>
</div>

<script type="text/javascript">
var so = new SWFObject("slideshow.swf", "gallery", "100%", "100%", "6", "#333333");
so.addParam("allowFullScreen", "true");
so.addVariable("file", "slideshow.php")
so.write("flashcontent");
</script>

Once again though, I could use a link to your page.

archanarj9
02-18-2012, 10:45 AM
Thank John once again but can't provide u the link as i m working on WAMP. Still need to know where to put the code in Flash as i m using it for First time. I m new in Development field.Will appreciate ur Help Thank u so much.

I don't know why my slideshow.php is Not working and also i can't find the place where its called by flash.though slideshow.php is okay as now its error free on opening it separately. pls Help me.

http://flashnifties.com/products/xml-flash-slideshow/demos/

This is the link from where is downloaded Flash.Its Demo4 i m using.Pls Help me.

jscheuer1
02-18-2012, 04:03 PM
I'm using WAMP too. That demo doesn't have a place to put slideshow.php because it's hard coded into loader.swf - or at least that's what I'm assuming is going on. So in theory you could decompile loader.swf and change the reference for slideshow.xml to slideshow.php or use .htaccess to make the server parse xml as php (I mentioned this before, but I think it's a bad idea - could work out well though, especially on WAMP where strict <?php tags are required, without that, the opening xml declaration might be mistaken for an opening php declaration). Or use PHP to create the slideshow.xml file on the fly at runtime.

I don't have an up to date Flash decompiler, editor or compiler. I tried the other two methods and they both worked.

The .htaccess method is probably better as long as it works. Here's how it goes -

Create a file named .htaccess - just the dot and the extension no filename. In it put this:


AddType application/x-httpd-php .xml

Save that as .htaccess and put it in the same folder with your loader.html and other files for this demo.

and rename your current slideshow.php file back to slideshow.xml. It will now be parsed as PHP by the server and seen by the the loader.swf as xml. That's it for the .htaccess method.

Now you can only do one or the other of these two methods, Not Both.

For this second approach I renamed loader.html to loader.php and added this highlighted bit at the top:


<?php
include 'slideshow.php';
?>
<!-- saved from url=(0013)about:internet -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>loader</title>
<script language="JavaScript" typ

And this is the contents of the slideshow.php file for this approach:


<?php
file_put_contents('slideshow.xml', '<?xml version="1.0" encoding="iso-8859-1"?>
<slideshow displayTime="5"
transitionSpeed=".7"
transitionType="Fade"
motionType="None"
motionEasing="easeInOut"
randomize="false"
slideshowWidth="400"
slideshowHeight="220"
slideshowX="center"
slideshowY="0"
bgColor="FFFFFF"
bgOpacity="100"
useHtml="true"
showHideCaption="false"
captionBg="000000"
captionBgOpacity="0"
captionTextSize="11"
captionTextColor="FFFFFF"
captionBold="false"
captionPadding="7"
showNav="false"
autoHideNav="false"
navHiddenOpacity="40"
navX="335"
navY="193"
btnColor="FFFFFF"
btnHoverColor="FFCC00"
btnShadowOpacity="85"
btnGradientOpacity="20"
btnScale="120"
btnSpace="7"
navBgColor="333333"
navBgAlpha="0"
navCornerRadius="0"
navBorderWidth="1"
navBorderColor="FFFFFF"
navBorderAlpha="0"
navPadding="8"
tooltipSize="8"
tooltipColor="000000"
tooltipBold="true"
tooltipFill="FFFFFF"
tooltipStrokeColor="000000"
tooltipFillAlpha="80"
tooltipStroke="0"
tooltipStrokeAlpha="0"
tooltipCornerRadius="8"
loaderWidth="200"
loaderHeight="1"
loaderColor="FF0000"
loaderOpacity="100"

attachCaptionToImage="true"
cropImages="false"
slideshowMargin="0"
showMusicButton="false"
music="images/music.mp3"
musicVolume="50"
musicMuted="false"
musicLoop="true"
watermark=""
watermarkX="625"
watermarkY="30"
watermarkOpacity="100"
watermarkLink=""
watermarkLinkTarget="_blank"
captionsY="bottom"
>
<image img="images/image1.jpg" customtitle="Camomile" />
<image img="images/image2.jpg" customtitle="Bells" />
<image img="images/image3.jpg" customtitle="Market" />
</slideshow>', LOCK_EX);
?>

to prove that it works, I then deleted the slideshow.xml file and launched loader.php - it worked.

What should happen is each time loader.php is run, it will create a new slideshow.xml file. I used the LOCK_EX flag so that if one user is logged on and writing a slideshow.xml at the same time as another user, only one slideshow.xml file will be written and used by both users, without risk of producing a corrupt slideshow.xml file.

Again, use only one or the other of these two methods, not both.

archanarj9
02-20-2012, 06:28 AM
Thank You So Much John :) I m so Happy that i learned so much for you. Your are Genius my friend. Pls Keep on Helping Like This.Thank you for the proper guidance you hv give. Now can u pls let me bit more abt PHP. Is it possible to create video from images and audio ? If yes then How ? I m Looking for this concept. Thanks in advance.

archanarj9
02-20-2012, 06:47 AM
This is the code in PHP which is working fine.
mysql_connect("localhost","root","");
mysql_select_db("vidiful");
$result=mysql_query("select * from create_video where id=9");
if($result)
{
$row=mysql_fetch_array($result);
echo $row['musics'];
echo $row['images'];
echo $row['img2'];
echo $row['img3'];
echo $row['img4'];
}
But when i am Pasting the same code in XML is showing me Error Bdw. I m Proceeding with John First option with .htaccess file. Pls suggest me.

jscheuer1
02-20-2012, 06:56 PM
As I said, I don't do database code. But, since you say you're using the .htaccess method, I'm assuming you tested it first with the slideshow.xml like so:


<?php
header ("content-type: application/xml");
echo '<?xml version="1.0" encoding="iso-8859-1"?>
<slideshow displayTime="5"
transitionSpeed=".7"
transitionType="Fade"
motionType="None"
motionEasing="easeInOut"
randomize="false"
slideshowWidth="400"
slideshowHeight="220"
slideshowX="center"
slideshowY="0"
bgColor="FFFFFF"
bgOpacity="100"
useHtml="true"
showHideCaption="false"
captionBg="000000"
captionBgOpacity="0"
captionTextSize="11"
captionTextColor="FFFFFF"
captionBold="false"
captionPadding="7"
showNav="false"
autoHideNav="false"
navHiddenOpacity="40"
navX="335"
navY="193"
btnColor="FFFFFF"
btnHoverColor="FFCC00"
btnShadowOpacity="85"
btnGradientOpacity="20"
btnScale="120"
btnSpace="7"
navBgColor="333333"
navBgAlpha="0"
navCornerRadius="0"
navBorderWidth="1"
navBorderColor="FFFFFF"
navBorderAlpha="0"
navPadding="8"
tooltipSize="8"
tooltipColor="000000"
tooltipBold="true"
tooltipFill="FFFFFF"
tooltipStrokeColor="000000"
tooltipFillAlpha="80"
tooltipStroke="0"
tooltipStrokeAlpha="0"
tooltipCornerRadius="8"
loaderWidth="200"
loaderHeight="1"
loaderColor="FF0000"
loaderOpacity="100"

attachCaptionToImage="true"
cropImages="false"
slideshowMargin="0"
showMusicButton="false"
music="images/music.mp3"
musicVolume="50"
musicMuted="false"
musicLoop="true"
watermark=""
watermarkX="625"
watermarkY="30"
watermarkOpacity="100"
watermarkLink=""
watermarkLinkTarget="_blank"
captionsY="bottom"
>
<image img="images/image1.jpg" customtitle="Camomile" />
<image img="images/image2.jpg" customtitle="Bells" />
<image img="images/image3.jpg" customtitle="Market" />
</slideshow>';
?>

If that worked, then once you modify it with your database code, you can view it in the browser directly for errors.

archanarj9
02-21-2012, 05:28 AM
Hey John Thanks once again For ur Reply but this time i didnot get u. Can u pls explain in details and i m not using .htaccess method. i m using the one u said to change into PHP. Thanks Once again. Pls Reply soon

jscheuer1
02-21-2012, 10:05 AM
I m Proceeding with John First option with .htaccess file. Pls suggest me.


i m not using .htaccess method. i m using the one u said to change into PHP. Thanks Once again. Pls Reply soon

I have no idea what you're doing.