Skip to content

Instantly share code, notes, and snippets.

@sunny
Created April 12, 2011 09:50
Show Gist options
  • Save sunny/915263 to your computer and use it in GitHub Desktop.
Save sunny/915263 to your computer and use it in GitHub Desktop.
<?
// Crée un fichier à partir d'un string, retourne le path complet vers le nouveau fichier
function create_file_from_string($string, $filename) {
$filename = LIB_PATH . '/tmp/' . $filename;
$handle = @fopen($filename, 'w+');
if (!$handle)
throw new Exception(sprintf(_("Impossible d'ouvrir le fichier %s en écriture !"), $filename));
if ($string) {
$ok = @fwrite($handle, $string);
if (!$ok) {
@fclose($handle);
new Exception(sprintf(_("Impossible d'écrire dans le fichier %s !"), $filename));
}
}
fclose($handle);
return $filename;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment