Jump to content

Write output to file.


Blamm

Recommended Posts

Hi.  SOrry of this is a really dumb question but I am a complete newbie to PHP.  I have managed to lash something up to extract XML from my media server and turn it into XSLT and  would really like to have the resulting file saved to a directory on my server without intervention but cant work out how to do it.

 

Here is my code:  Any help greatfully received

 

[pre]<?php

header('Content-type: application/xspf+xml');  // Sets the MIME type to XSPF

header('Content-Disposition: attachment; filename="playlist.xspf"'); //Sets the file name for the playlist.

$id = $_GET['id']; // Gets the ID passed by the URL

$url = "http://localhost:3689/rsp/db/".$id."?type=browse"; // Uses the ID to set the URL for querying the right playlist.

$dom = new domDocument();

  $dom->load("rsp2xspf.xsl"); // Loads the XSL file.

  $proc = new xsltprocessor;

  $xsl = $proc->importStylesheet($dom);

  $document = new DomDocument();

  $document->load("$url"); // Loads the XML from the RSP query

  print $proc->transformToXml($document);

  ?>[/pre]

Link to comment
https://forums.phpfreaks.com/topic/198432-write-output-to-file/
Share on other sites

Think you're best served by the file_put_contents function. For more info take a look here:

 

http://uk3.php.net/manual/en/function.file-put-contents.php

 

If your server is running on a unix server, your script will need to have write permissions for the directory. The command you would need for this is chmod, you will need ftp or command line access to the server to use it. Google it for more information! A big part of web development is research. Good luck!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.