Author Topic: save.php source code not available for download.  (Read 37048 times)

Infiniti Productions LLC

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Infiniti Productions LLC
save.php source code not available for download.
« on: February 24, 2007, 12:18:58 am »
Is there any way I could take a look at the PHP code on save.php in the flash/php/xml example posted on your site.  I have been looking all day for a tutorial on the topic.

You are the only one.

Thank you so much.

Brian.

viulian

  • Administrator
  • Newbie
  • *****
  • Posts: 38
  • Karma: +1/-0
    • View Profile
Re: save.php source code not available for download.
« Reply #1 on: February 24, 2007, 12:55:51 pm »
Thanks for the kind words :)

I've pasted the code below. It is minimalistic so it can be easily adapted to any use..

Code: [Select]
<?php
//Capture data from $_POST array
$myxml $GLOBALS['HTTP_RAW_POST_DATA'];
//Make one big string in a format Flash understand
//Open a file in write mode
$fp fopen("value.xml""w");
$ok fwrite($fp$myxml);
fclose($fp);

if (
$ok)
        
header('Location:http://hex.ro/files/flashxml/Display.html');
else
        echo 
"writing=Error&";

?>

I'll also update the webpage now..

Infiniti Productions LLC

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Infiniti Productions LLC
Re: save.php source code not available for download.
« Reply #2 on: February 24, 2007, 08:21:53 pm »
thank you.  This is exactly what I needed. You rock.

Infiniti Productions LLC

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Infiniti Productions LLC
Re: save.php source code not available for download.
« Reply #3 on: February 25, 2007, 02:52:34 am »
Thank you again, The HTTP_RAW_POST_DATA was what I needed.

I was wondering if you could tell me what can be done to the PHP code above to make is so the window does not pop open upon completion of the xml save.  I commented out:

if ($ok)
        header('Location:http://hex.ro/files/flashxml/Display.html');
else
        echo "writing=Error&";


And that made is so display.html does not open (I am only interested in the XML creation), however, a blank window still open and has the path and filename of the .php file.

Again, I thank you so much. You have been very helpful.

Infiniti Productions LLC

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Infiniti Productions LLC
Re: save.php source code not available for download.
« Reply #4 on: February 25, 2007, 02:56:07 am »
also... how difficult is it to make the new nodes add onto value.xml as apposed to wiping the xml file clean each time?

viulian

  • Administrator
  • Newbie
  • *****
  • Posts: 38
  • Karma: +1/-0
    • View Profile
Re: save.php source code not available for download.
« Reply #5 on: February 25, 2007, 10:59:54 am »
Thanks :)

About appending nodes to an XML file instead of writing it down from zero... there are a couple of solutions.
If you run PHP 5, you can use http://php.net/simplexml to read the XML sent from flash [pick up the nodes that is] and then read update the XML on disk with the new nodes.

For older PHPs, you can search the web for something like PHP XML class, or PHP xml simple.. and pick up the one best suited for your goal.

But there is a problem: what would happen if two users would click 'Save' and then the web server will try to update the XML on disk with two changes simultaneously ? One of the changes will be lost when the script that runs last will update the file on disk.
If you want to save data on disk and plan on offering the flash to >10 users which might click Save at the same time, I guess it's better if you save each request separately. Then, when you want to access the data saved as XML, you will just read all the files and create a big XML and then use that..

---

About the redirect ...
I think it will try to do the redirect anyway (if you press on Save because it does a POST) so the choice would be to redirect to the same page containing the flash which lets the user enter the data (basically a reload).
Or maybe you can change the 'Save' button properties and make it not to be a submit button, but a simple button (which won't trigger a redirect but just make a background call to the save.php script - AJAX like behaviour, for example).

I don't have Macromedia anymore - did this tutorial a year ago or so, so that as far as I can help..

Infiniti Productions LLC

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Infiniti Productions LLC
Re: save.php source code not available for download.
« Reply #6 on: February 26, 2007, 03:23:18 pm »
Again thank you.  I think by the end of this I might know PHP.  Thank you for the tip about >10 users although it is for a website customer's testimonials - i doubt it will become very popular.  You have been great.

viulian

  • Administrator
  • Newbie
  • *****
  • Posts: 38
  • Karma: +1/-0
    • View Profile
Re: save.php source code not available for download.
« Reply #7 on: February 26, 2007, 09:29:54 pm »
Thank you too :) and good luck!

Infiniti Productions LLC

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Infiniti Productions LLC
Re: save.php source code not available for download.
« Reply #8 on: February 26, 2007, 10:34:48 pm »
its working very well... i figured something out.
if you just replace your "w" with "a" in fopen, it will append onto the xml file instead of overwriting.

Peace.

viulian

  • Administrator
  • Newbie
  • *****
  • Posts: 38
  • Karma: +1/-0
    • View Profile
Re: save.php source code not available for download.
« Reply #9 on: February 26, 2007, 10:45:17 pm »
Well :) "a" means append..
I don't think it will be a well formed XML what you get, because you will have something like:

Code: [Select]
<root>
  <value>
    10
  </value>
</root>
<root>
  <value>
    10
  </value>
</root>

Which is not a good XML as it doesn't have a root node - a single node that embeds everything else..

But if you can parse this structure which is not a well formed XML, then it's ok I guess.

For more reading: http://en.wikipedia.org/wiki/XML where it says:

Every XML document must have exactly one top-level root element (alternatively called the document element), so the following would also be a malformed XML document: it has two top-level thing elements, with no overall parent element encasing them both.

<?xml version="1.0" encoding="UTF-8"?>
<!-- WRONG! NOT WELL-FORMED XML! -->
<thing>Thing one</thing>
<thing>Thing two</thing>


daryy

  • Guest
Re: save.php source code not available for download.
« Reply #10 on: February 08, 2009, 07:04:35 am »
thanks! Really helps!Discount Compressor offers Oldsmobile AC Compressor with the highest quality, a product that only dealers previously had! Discountcompressor.com now offers ...
« Last Edit: February 10, 2010, 06:22:31 am by daryy »