$filename,
'title' => sprintf('fichier de type %s', $ftype)
);
} else {
$pano = array(
'comment' => sprintf('%s', $filename),
'title' => ''
);
}
$pano['filename'] = $filename;
$ret[] = $pano;
}
}
return $ret;
}
public static function strip_extension($filename) {
/** Removes the extension from a file name
* @return the stripped name
*/
return preg_replace('/\.[^.]+$/', '', $filename);
}
public static function php2ini($v) {
/** convert php var to a string representing it in an ini file.
* @return a string, ready to be inserted into a ini file.
*/
if (is_numeric($v)) {
return $v;
}
$type = gettype($v);
switch($type) {
case 'boolean': return $v ? "true" : "false";
default: return '"'.$v.'"';
}
return $v;
}
public static function get_unique_filepath($path) {
/** To handle uploads with same name : for a given path, suffix it with _
(keeping trailing extension)
* till it find a non-preexistant_path and returns it.
*/
if (file_exists($path)) {
$info = pathinfo($path);
$extension = $info['extension'];
$remain = self::strip_extension($path);
$n = 0;
do {
$n++;
$fn = sprintf('%s_%d.%s', $remain, $n, $extension);
} while (file_exists($fn));
return $fn;
} else {
return $path;
}
}
public static function relative_redirect($extra) {
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: http://$host$uri/$extra");
}
}
?>