<?php # # Copyright(C) 2004-2007 INL # Written by Eric Leblond <regit@inl.fr> # Vincent Deffontaines <gryzor@inl.fr> # Jean Gillaux <jean@inl.fr> # Damien Boucard <damien.boucard AT inl.fr> # # $Id: file_function.php 17927 2009-02-16 13:16:09Z haypo $ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see <http://www.gnu.org/licenses/>. # # require_once('function.php'); function del_file($filename=''){ global $datadir; if (!check_filename($filename)) return false; if ($filename==''){ return false; } $filename = $datadir.'/'.$filename; if (!file_exists($filename)) return false; return @unlink($filename); } function cmp_file($elt1, $elt2){ if ($elt1["mtime"] == $elt2["mtime"]) { return 0; } return ($elt2["mtime"] > $elt1["mtime"]) ? 1: -1; } function file_list(){ global $datadir; $files = array(); $res = array(); $dir = @opendir($datadir); if (! $dir) { add_log(sprintf(_('Could not open directory "%s"! Please check your configuration.'), $datadir)); return Array(); } clearstatcache(); while(($file = readdir($dir)) !== false) { if ($file == '.' or $file == '..') continue; if (is_dir($file)) continue; if (substr($file, -4) != '.xml') continue; $mtime = stat($datadir."/".$file); $files[] = array("file" => $file, "mtime" => $mtime["mtime"]); } closedir($dir); usort($files,"cmp_file"); foreach($files as $elt) { $res[] = $elt["file"]; } return($res); } /* * This function read opened file represented by handler * and returns array of strings, each a line from the file */ function file_readlines($filename) { $file = fopen($filename, 'r'); if(!$file) return Array(); $lines= Array(); while (!feof($file)){ $lines[] = rtrim(fgets($file)); } fclose($file); return $lines; } function rename_if_exists($src,$dst){ if (file_exists($src)){ rename($src,$dst); } } function filenameWithoutXml($filename) { return ereg_replace("\.xml$", "", basename($filename)); } ?>