Duplicate a file and modifies it with PHP

Function php list to duplicate files


Simple function programmed in PHP lists to use, opens to a file and it duplicate with the possibility of realising changes in directly to the flight. We only needed to pass to the function as minimum the first value that serious the file to duplicate and the second S-value the name of the new file.


/* TEST OF THE FUNCTION * <? php I throw to file_duplicar (€˜file_original.php€™, €˜nuevo_archivo.php€™); >

/* FUNCTION THAT OPENS FILE PUBLISHES AND IT NEW GUARD AS ONE * function to file_duplicar ($directorio_original, $directorio_nuevo) \ {if (file_exists ($directorio_original)) \ {$file = fopen ($directorio_original, €˜r€™); while (! feof ($file)) \ {$name = fgets ($file); //ALL THE LINES ARE STORED IN THE VARIABLE $LINEAS $LINEAS [] = $NAME; } fclose ($file); } //NOW WE MODIFIED LINE 2 For example, IN the VARIABLE $lineas would be position 1, (we began by the 0) //ELIMINATES LINE #unset ($lineas [2]); //MODIFIES LINE #$lineas [2] = €˜defines (\ €˜APP \€™, \€ .APP. €™ \ €˜); €˜. €œ\ n€; $lineas = array_values ($lineas); //WE KEPT LINE TO LINE IN a NEW FILE FILE $file = fopen ($directorio_nuevo, €œw€); foreach ($lineas $linea ace) \ {fwrite ($file, $linea); } if (fclose ($file))\ {return TRUE; }}