Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Send Form Data to XML file

    Good day folks!

    I am just getting start in PHP and really could use some help.
    I am trying to export an array into a XML file.

    Some Background:
    I currently working with a PHP class (Media Grabber) that grabs images from a URL, sorta like facebook & google.I am having issues posting that data after it has been captured.

    Here is the process flow

    User Enters URL
    $imageMediaGrabber will do the heavy lifting
    Grab array of images
    Export to images.XML


    I am stuck after $imageMediaGrabber has the array. Please advise as to how I can export to XML. Please take a look below and let me know what you think. The code in question is 2 or 3 lines from the closing php tag. A million thanks!

    Code:
    <?php
    include 'tut/connect.php';
    require_once dirname(__FILE__)."/bin/wlWmg.php";
    require_once dirname(__FILE__)."/demo-utils.php";
    $url = wlWmgUtils::getArrayValue($_POST, 'user_url', wlWmgUtils::getArrayValue($_GET, 'user_url', null));
    ?>
    
    
    
    <?php
    if (isset($_REQUEST['Submit'])) {
    # THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE
    $sql = "INSERT INTO $db_table(user_name,user_url) values ('".mysql_real_escape_string(stripslashes($_REQUEST['user_name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['user_url']))."')";
    if($result = mysql_query($sql ,$db)) {
    echo '<h1>Thank you</h1><br/><p>Your information has been entered into our database</p>"';
    } else {
    echo "ERROR: ".mysql_error();
    }
    } else {
    ?>
    <form action="" id="form"  method="POST" enctype="multipart/form-data">
    <input type="text" name="user_name"><br>URL <br>
    <input type="text" name="user_url" id="user_url" value="
    <?php echo isset($url) ? $url : 'http://cnn.com';?>"/>
    <input type="submit" name="Submit" value="Submit"/>
    </form>
    <?php
    }
    ?>
    
    
    
    <?php
    if(!$image_extensions_active) {
        $image_extensions = null;
    }
    
    //the magic starts here ...
    //creating the image grabber object by giving some necessary parameters:
    //$url: url,
    //$image_extensions: the image extensions to grab (null means all)
    $imageMediaGrabber = new wlWmgImageGrabber($url, $image_extensions);
    
    //set download switch: if the images should be downloaded to localhost
    $imageMediaGrabber->setDoDownload($download);
    
    //limit filter: setting the media limit count to be grabbed
    if($limit_active) {
        $imageMediaGrabber->setLimit($limit);
    }
    
    //the processor will grab only the media founded inside the contents of the tag specified here
    if($tagslice_active) {
        $imageMediaGrabber->setGrabOnlyFromTagSlice($tagslice);
    }
    
    
    //grabbing
    if($url) {
        $imageMediaGrabber->grab();
    
        //HOW DO I GET THIS EXPORTED TO XML
        echo '<pre>'.print_r($imageMediaGrabber->getValidMediaNames(true), true).' </pre>';
    
    }
    
    ?>

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    can you post the output of echo
    PHP Code:
    <? print_r($imageMediaGrabber->getValidMediaNames(true);?>
    then perhaps we can help, you should just be able to iterate through the array (foreach()), build a string of XML data then write it using file_put_contents() or fopen() etc
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Tags for this Thread

    Posting Permissions

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