Fonte: http://www.php.net/manual/it/function.fopen.php

Codice PHP:
While PHP does not have a function to insert text into the middle of a file, it is not that complicated to do.

<?php
function addRSSItem($rssFile$firstItem$item){
    
// Backup file
    
if(!copy($rssFile'backup.rss')) die('Backup failed!');
    
// Store file contents in array
    
$arrFile file($rssFile);
    
// Open file for output
    
if(($fh fopen($rssFile,'w')) === FALSE){
        die(
'Failed to open file for writing!');
    }
    
// Set counters
    
$currentLine 0;
    
$cntFile count($arrFile);
    
// Write contents, inserting $item as first item
    
while( $currentLine <= $cntFile ){
        if(
$currentLine == $firstItemfwrite($fh$item);
        
fwrite($fh$arrFile[$currentLine]);
        
$currentLine++;
    }
    
// Delete backup
    
unlink('backup.rss');
}

$data "    <item>\n<title>$_POST['title]</title>\n".
  
"        <description>$_POST['description']</description>\n".
  
"        <pubDate>$_POST['date']</pubDate>\n".
  
"        <link>[url]http://www.site.com/mp3s/[/url]".
  
basename($_FILES['fullPath']['name'])."</link>".
  
"        <enclosure url=\"http://www.site.com/mp3s/".
  
basename($_FILES['fullPath']['name']).
  
"\" length=\"$_FILES[fullPath][size]\" type=\"audio/mpeg\" />".
  
"    </item>\n";
addRSSItem('/var/www/html/rss/podcast.rss',20,$data);
?>