PHP Flex File Download


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. /** ****************************************************************
  3.  * Working File Download XML Server Script for Flex
  4.  *
  5.  * MySnippets
  6.  * Free for use
  7.  *
  8.  * @author Jonnie Spratley
  9.  * @contact [email protected]
  10.  ******************************************************************* */
  11. /* Set the content type for the browser */
  12. header("Content-type: text/xml");
  13.  
  14. /* Establish a connection to database */
  15. $link = mysql_connect('localhost', 'spratley_guest', 'guest') or die('Could not connect: ' . mysql_error());
  16.  
  17. /* Select the database */
  18. mysql_select_db( 'spratley_tutorials', $link ) or die ( mysql_error() );
  19.  
  20. /* Build the query for the table */
  21. $query = "SELECT * FROM flex_uploads ORDER BY file_date DESC";
  22.  
  23. /* Execute the query on the table */
  24. $resultID = mysql_query( $query, $link ) or die( "Data not found." );
  25.  
  26. /* Set the header xml version */
  27. $xml_output = "<?xml version="1.0"?>n";
  28.  
  29. /* Set the root node for the xml */
  30. $xml_output .= "<files>n";
  31.  
  32. /* Loop through all records in the query and output */
  33. for( $x = 0 ; $x < mysql_num_rows( $resultID ) ; $x++ )
  34. {
  35. /* Result rows */
  36. $row = mysql_fetch_assoc( $resultID );
  37.  
  38. /* Set the child node */
  39. $xml_output .= "t<file>n";
  40.  
  41. /* Set every node inside the child file node (id) */
  42. $xml_output .= "tt<id>" . $row['file_id'] . "</id>n";
  43.  
  44. /* file_name table column */
  45. $xml_output .= "tt<name>" . $row['file_name'] . "</name>n";
  46.  
  47. /* file_size table column */
  48. $xml_output .= "tt<size>" . $row['file_size'] . "</size>n";
  49.  
  50. /* file_type table column */
  51. $xml_output .= "tt<type>" . $row['file_type'] . "</type>n";
  52.  
  53. /* file_url table column */
  54. $xml_output .= "tt<url>" . $row['file_url'] . "</url>n";
  55.  
  56. /* file_date table column */
  57. $xml_output .= "tt<date>" . $row['file_date'] . "</date>n";
  58.  
  59. /* Close the child file now and print the child file node out */
  60. $xml_output .= "t</file>n";
  61.  
  62. }/* Ends the loop */
  63.  
  64. /* Close the parent files node */
  65. $xml_output .= "</files>";
  66.  
  67. /* Output all of the xml */
  68. echo $xml_output;
  69.  
  70. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.