Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: How to code in XML files Using PHP

  1. #1
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question How to code in XML files Using PHP

    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.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,982
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    That's not valid xml. At the very least, that second <code> tag should be a closing tag:

    Code:
    </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 Code:
    <?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 Code:
    <?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

    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.
    Last edited by jscheuer1; 02-15-2012 at 04:05 PM. Reason: add question and info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    archanarj9 (02-18-2012)

  4. #3
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    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 :-

    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
    Last edited by jscheuer1; 02-18-2012 at 07:06 AM. Reason: Format

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,982
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    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.
    Last edited by jscheuer1; 02-18-2012 at 07:00 AM. Reason: more info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Need Help

    This is the code i have done in slideshow.php
    PHP Code:
    <?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. "
    Last edited by jscheuer1; 02-18-2012 at 08:26 AM. Reason: Format

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,982
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    That's never going to work. Try (slideshow.php):

    PHP Code:
    <?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>'
    ;
    ?>
    Last edited by jscheuer1; 02-18-2012 at 08:23 AM. Reason: switch header
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. The Following User Says Thank You to jscheuer1 For This Useful Post:

    archanarj9 (02-18-2012)

  9. #7
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Help Me

    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.

  10. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,982
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  11. The Following User Says Thank You to jscheuer1 For This Useful Post:

    archanarj9 (02-18-2012)

  12. #9
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    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.
    Last edited by jscheuer1; 02-18-2012 at 01:55 PM. Reason: format/merge

  13. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,982
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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:

    Code:
    <?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 Code:
    <?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.
    Last edited by jscheuer1; 02-18-2012 at 05:36 PM. Reason: clarity
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  14. The Following User Says Thank You to jscheuer1 For This Useful Post:

    archanarj9 (02-20-2012)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •