Exemple #1
0
function resizeImage()
{
    //lay duong dan file duoc request
    $request = $_SERVER['REQUEST_URI'];
    //lay ten file
    $tmp_request = explode('/', $request);
    $case = count($tmp_request);
    $image_name = $tmp_request[$case - 1];
    //type resize
    $resize_type = $tmp_request[$case - 2];
    //echo $image_name;
    $resource_img = get_picture_dir($image_name) . '/' . $image_name;
    $resource_img = '..' . $resource_img;
    if (!file_exists($resource_img)) {
        error_404_document();
    }
    //echo file_get_contents($resource_img);exit();
    $images = new Image($resource_img);
    $imageinfo = $images->getImageInfo();
    if ($imageinfo['height'] == null || $imageinfo['height'] == 0) {
        error_404_document();
    }
    //kich thuoc resize
    $array_resize = array('large' => array(480, 360), 'medium' => array(240, 180), 'medium2' => array(145, 95), 'small' => array(106, 80), 'thumb' => array(50, 50), 'mobile' => array(640, 400), 'mobile_medium' => array(320, 200), 'mobile_small' => array(120, 75), 'mobile_low' => array(640, 400, 30), 'mobile_medium_low' => array(320, 200, 30), 'mobile_small_low' => array(120, 75, 30));
    if (!isset($array_resize[$resize_type])) {
        error_404_document();
    }
    //image name file no extension
    $filesavename = explode('.', $image_name);
    $count3 = count($filesavename);
    if ($count3 > 1) {
        unset($filesavename[$count3 - 1]);
    }
    $filesavename = implode('.', $filesavename);
    $pathsave = '..' . get_picture_dir($image_name, $resize_type);
    //nếu thư mục ảnh không tồn tại thì tạo mới
    if (!file_exists($pathsave)) {
        mkdir($pathsave, 0755, 1);
    }
    //echo $pathsave;die();
    //kich thuoc resize ok -> tao file voi kich thuoc phu hop
    $r_width = $array_resize[$resize_type][0];
    $r_height = $array_resize[$resize_type][1];
    if (isset($array_resize[$resize_type][2])) {
        $r_quality = $array_resize[$resize_type][2];
    } else {
        $r_quality = 100;
    }
    if ($resize_type == 'organic') {
        $images->resize($r_width, $r_height, 'fit', 'c', 'c', $r_quality);
    } else {
        $images->resize($r_width, $r_height, 'crop', 'c', 'c', $r_quality);
    }
    $images->save($filesavename, $pathsave);
    header("HTTP/1.0 200 OK");
    $images->display();
}
                      new_title,
                      new_picture,
                      new_teaser,
                      cat_id,
                      cat_name,
                      new_date,
                      new_tags,
                      new_view
               FROM news
               LEFT JOIN categories ON cat_id = new_cat_id
               WHERE new_id = ' . $iNews;
$db_detail = new db_query($sql_detail);
$detail_data = mysqli_fetch_assoc($db_detail->result);
unset($db_detail);
if (!$detail_data) {
    error_404_document();
}
//tăng view cho tin
$db_update_view = new db_execute('UPDATE news SET new_view = new_view + 1 WHERE new_id = ' . $iNews);
unset($db_update_view);
//lấy chi tiết tin
$sql_news_content = 'SELECT ndt_content FROM news_detail WHERE ndt_id = ' . $iNews;
$db_content = new db_query($sql_news_content);
$row = mysqli_fetch_assoc($db_content->result);
unset($db_content);
$detail_data['new_detail'] = $row['ndt_content'];
$datetime_facebook = $detail_data['new_date'];
$datetime_detail_timestamp = $detail_data['new_date'];
$detail_data['new_date'] = getDateTime(1, 1, 1, 1, '', $detail_data['new_date']);
$detail_data['link_cat'] = generate_cat_url($detail_data);
$detail_data['new_picture'] = get_picture_path($detail_data['new_picture'], 'large');
Exemple #3
0
    function db_query($query, $file_include_name = "")
    {
        $generate_time = microtime_float();
        $dbinit = new db_init();
        $this->links = @mysqli_connect($dbinit->server, $dbinit->username, $dbinit->password);
        if (!$this->links) {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
            echo '<meta name="revisit-after" content="1 days">';
            echo "<center>";
            echo "Chào bạn, trang web bạn yêu cầu hiện chưa thể thực hiện được. <br>";
            echo "Xin bạn vui lòng đợi vài giây rồi ấn <b>F5 để Refresh</b> lại trang web <br>";
            echo "</center>";
            exit;
        }
        $db_select = mysqli_select_db($this->links, $dbinit->database);
        $time_start = $this->microtime_float();
        mysqli_query($this->links, "SET NAMES 'utf8'");
        $this->result = mysqli_query($this->links, $query);
        $time_end = $this->microtime_float();
        $time = $time_end - $time_start;
        if ($time >= $this->time_slow_log) {
            $path = $_SERVER['DOCUMENT_ROOT'] . "/log/slow/";
            $filename = date("Y_m_d_H") . "h.txt";
            $url = $file_include_name;
            if (file_exists($path . $filename)) {
                $str = file_get_contents($path . $filename);
                $str = number_format($time, 10, ".", ",") . " :  " . $query . chr(13) . chr(13) . $str;
                file_put_contents($path . $filename, "Thoi gian : " . date("H:i") . " : " . $url . "--------------------------------------------->" . chr(13) . number_format($time, 10, ".", ",") . " :  " . $str);
            } else {
                file_put_contents($path . $filename, "Thoi gian : " . date("H:i") . " : " . $url . "--------------------------------------------->" . chr(13) . number_format($time, 10, ".", ",") . " :  " . $query);
                @chmod($path . $filename, 0644);
            }
        }
        if (!$this->result) {
            $path = $_SERVER['DOCUMENT_ROOT'] . "/log/error/";
            $filename = date("Y_m_d_H") . "h.txt";
            $str_error = '';
            $str = '';
            $error = "(" . mysqli_errno($this->links) . ") " . mysqli_error($this->links);
            mysqli_close($this->links);
            if (file_exists($path . $filename)) {
                $str = file_get_contents($path . $filename);
            }
            $str_error .= "IP:" . $_SERVER['REMOTE_ADDR'] . "Thoi gian : " . date("H:i") . " " . $_SERVER['REQUEST_URI'] . chr(13);
            $str_error .= "Loi o file : " . $file_include_name . chr(13);
            $str_error .= "Loi query : " . $error . chr(13);
            $str_error .= "Database : " . $dbinit->database . chr(13);
            $str_error .= "Query : " . $query . chr(13);
            $str_error .= "//------------------------------------------------------------------------------------------------->";
            $str_error = $str_error . chr(13) . $str;
            @file_put_contents($path . $filename, $str_error);
            @chmod($path . $filename, 0644);
            if ($_SERVER["SERVER_NAME"] == "localhost") {
                die('<p style="font-size:13px;margin:30px auto; width : 900px;
			                font-family:Tahoma;color:#333;padding:24px 15px;background : #f9d386;text-align:center;">
			                <span style="color:#d60c0c;font-weight:bold;text-transform:uppercase;display:block">
			                Error in query string : </span>
			                <br><b style="color:#d60c0c;">ERROR</b> :  ' . $error . '<br><b style="color:#d60c0c;">QUERY</b> :' . $query . '</p>');
            }
            error_404_document();
            die;
        }
        unset($dbinit);
    }