<?php
class upload{
    
    /*function haccp($haccp){
        //direktori gambar
        $vdir_upload = "../../../../file/haccp/";
        $vfile_upload = $vdir_upload . $haccp;

        //Simpan gambar dalam ukuran sebenarnya
        move_uploaded_file($_FILES["files"]["tmp_name"], $vfile_upload);

    }*/
    
    function produk($produk,$link){
        ///direktori gambar
        $vdir_upload = $link."view/assets/img/produk/";
        $vfile_upload = $vdir_upload . $produk;

        //Simpan gambar dalam ukuran sebenarnya
        move_uploaded_file($_FILES["gambar"]["tmp_name"], $vfile_upload);

        //identitas file asli
        $im_src = imagecreatefromjpeg($vfile_upload);
        $src_width = imageSX($im_src);
        $src_height = imageSY($im_src);

        //Simpan dalam versi small 350 pixel
        //Set ukuran gambar hasil perubahan
        $dst_width = 450;
        $dst_height = ($dst_width/$src_width)*$src_height;

        //proses perubahan ukuran
        $im = imagecreatetruecolor($dst_width,$dst_height);
        imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);

        //Simpan gambar
        imagejpeg($im,$vdir_upload . "small_" . $produk);

        //Hapus gambar di memori komputer
        imagedestroy($im_src);
        imagedestroy($im);

    }

    function post($post,$link){
        ///direktori gambar
        $vdir_upload = $link."view/assets/img/post/";
        $vfile_upload = $vdir_upload . $post;

        //Simpan gambar dalam ukuran sebenarnya
        move_uploaded_file($_FILES["gambar"]["tmp_name"], $vfile_upload);
    

    }

    function page($page,$link){
        ///direktori gambar
        $vdir_upload = $link."view/assets/img/page/";
        $vfile_upload = $vdir_upload . $page;

        //Simpan gambar dalam ukuran sebenarnya
        move_uploaded_file($_FILES["gambar"]["tmp_name"], $vfile_upload);

    }

    function fp2($gambar,$link){
        ///direktori gambar
        $vdir_upload = $link."view/assets/img/";
        $vfile_upload = $vdir_upload . $gambar;

        //Simpan gambar dalam ukuran sebenarnya
        move_uploaded_file($_FILES["gambar"]["tmp_name"], $vfile_upload);

    }

    function rekanan($rekanan,$link){
        ///direktori gambar
        $vdir_upload = $link."view/assets/img/rekanan/";
        $vfile_upload = $vdir_upload . $rekanan;

        //Simpan gambar dalam ukuran sebenarnya
        move_uploaded_file($_FILES["gambar"]["tmp_name"], $vfile_upload);

    }

    function lists($lists,$link){
        ///direktori gambar
        $vdir_upload = $link."view/assets/img/list/";
        $vfile_upload = $vdir_upload . $lists;

        //Simpan gambar dalam ukuran sebenarnya
        move_uploaded_file($_FILES["gambar"]["tmp_name"], $vfile_upload);

    }

    function galeri($galeri,$link){
        ///direktori gambar
        $vdir_upload = $link."view/assets/img/galeri/";
        $vfile_upload = $vdir_upload . $galeri;

        //Simpan gambar dalam ukuran sebenarnya
        move_uploaded_file($_FILES["gambar"]["tmp_name"], $vfile_upload);

        //identitas file asli
        $im_src = imagecreatefromjpeg($vfile_upload);
        $src_width = imageSX($im_src);
        $src_height = imageSY($im_src);

        //Simpan dalam versi small 350 pixel
        //Set ukuran gambar hasil perubahan
        $dst_width = 450;
        $dst_height = ($dst_width/$src_width)*$src_height;

        //proses perubahan ukuran
        $im = imagecreatetruecolor($dst_width,$dst_height);
        imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);

        //Simpan gambar
        imagejpeg($im,$vdir_upload . "small_" . $galeri);

        //Hapus gambar di memori komputer
        imagedestroy($im_src);
        imagedestroy($im);

    }
    
    function profile($profile,$link){
        //direktori gambar
        $vdir_upload = $link."view/file/profile/";
        $vfile_upload = $vdir_upload . $profile;

        //Simpan gambar dalam ukuran sebenarnya
        move_uploaded_file($_FILES["gambar"]["tmp_name"], $vfile_upload);

        //identitas file asli
        $im_src = imagecreatefromjpeg($vfile_upload);
        $src_width = imageSX($im_src);
        $src_height = imageSY($im_src);

        //Simpan dalam versi small 350 pixel
        //Set ukuran gambar hasil perubahan
        $dst_width = 450;
        $dst_height = ($dst_width/$src_width)*$src_height;

        //proses perubahan ukuran
        $im = imagecreatetruecolor($dst_width,$dst_height);
        imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);

        //Simpan gambar
        imagejpeg($im,$vdir_upload . "small_" . $profile);

        //Hapus gambar di memori komputer
        imagedestroy($im_src);
        imagedestroy($im);
    }
}

