Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-11-2012, 05:07 PM   PM User | #1
ddot22
New to the CF scene

 
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ddot22 is an unknown quantity at this point
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>';

}

?>
ddot22 is offline   Reply With Quote
Old 05-12-2012, 04:26 PM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,890
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
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)
firepages is offline   Reply With Quote
Reply

Bookmarks

Tags
array, forms, xml

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:51 PM.


Advertisement
Log in to turn off these ads.