lunes, 31 de agosto de 2009

PHP getExtension getArchivo getPath getFilesInFolder deleteFilesInFolder nextIdOnTable

<?php
function getExtension($nombre)
{
 $fileName = $nombre;
 $fileNameParts = explode( ".", $fileName );
 $fileExtension = end( $fileNameParts );
 $fileExtension = strtolower( $fileExtension );
 return $fileExtension;
}
?>

<?php
// http://server02/Sweet%20Victorian/Web%202009/web/media/images/1_1.jpg -> retorna: 1_1.jpg
function getArchivo($path)
{
    $fileName = $path;
    $fileNameParts = explode( "/", $fileName );
    $arch = end( $fileNameParts );
    return $arch;
}
?>

<?php
// http://server02/Sweet%20Victorian/media/images/1_1.jpg
// -> retorna: http://server02/Sweet%20Victorian/media/images/
function getPath($path)
{
    $fileName = $path;
    $fileNameParts = explode( "/", $fileName );
    $arch = end( $fileNameParts );
    
    $str = str_replace($arch, "", $path);
    
    return $str;
}
?>

<?php
function getFilesInFolder($path)
{
    $files = array();
    
    $dirHandle = opendir($path);
    while($file = readdir($dirHandle))
    {
        if($file != "." && $file != "..")
        {
            $files[] = $file;
        }
    }
    closedir($dirHandle);

    return $files;
}

$pathFuente = "../carpeta";

echo "<pre>";
print_r(getFilesInFolder($pathFuente));
echo "</pre>";
?>

<?php
//$archivos = getFilesInFolder($pathTMP, $formats="png,jpg,jpeg,gif,tif");
function getFilesInFolder($path, $formats = "")
{
    $filtrarPorExtension = ($formats > "")? true:false;
    $files = array();
    
    $dirHandle = opendir($path);
    while($file = readdir($dirHandle))
    {
        if($file != "." && $file != "..")
        {
            if ($filtrarPorExtension)
            {
                $ext = getExtension($file);
                if (stristr($formats, $ext))
                {
                    $files[] = $file;
                }
            }
            else
            {
                $files[] = $file;
            }
            
        }
    }
    closedir($dirHandle);

    return $files;
}
?>

<?php
function deleteFilesInFolder($path, $formats = "")
{
    $files = getFilesInFolder($path, $formats);
    
    $total = 0;
    foreach ($files as $archivo)
    {
        @unlink($path.$archivo);
        $total++;
    }

    return $total;
}
?>

<?php
function nextIdOnTable($tablename)
{
    $next_increment = -1;
    $qShowStatus = "SHOW TABLE STATUS LIKE '$tablename'";
    $qShowStatusResult = mysql_query($qShowStatus) or die ( "Query failed: " . mysql_error() . "<br/>" . $qShowStatus );
    
    $row = mysql_fetch_assoc($qShowStatusResult);
    $next_increment = $row['Auto_increment'];
    
    return $next_increment;
}
?>

No hay comentarios:

Publicar un comentario