while (file_exists(NV_ROOTDIR . '/' . $path . '/' . $file)) { $file = preg_replace('/^(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $width . '_' . $height . '_' . $i . '\\2', $imagename); ++$i; } if (isset($array_thumb_config[$path])) { $thumb_config = $array_thumb_config[$path]; } else { $thumb_config = $array_thumb_config['']; $_arr_path = explode('/', $path); while (sizeof($_arr_path) > 1) { array_pop($_arr_path); $_path = implode('/', $_arr_path); if (isset($array_thumb_config[$_path])) { $thumb_config = $array_thumb_config[$_path]; break; } } } $createImage = new NukeViet\Files\Image(NV_ROOTDIR . '/' . $path . '/' . $imagename, NV_MAX_WIDTH, NV_MAX_HEIGHT); $createImage->resizeXY($width, $height); $createImage->save(NV_ROOTDIR . '/' . $path, $file, $thumb_config['thumb_quality']); $createImage->close(); if (isset($array_dirname[$path])) { $did = $array_dirname[$path]; $info = nv_getFileInfo($path, $file); $info['userid'] = $admin_info['userid']; $db->query("INSERT INTO " . NV_UPLOAD_GLOBALTABLE . "_file\n\t\t\t\t\t\t\t(name, ext, type, filesize, src, srcwidth, srcheight, sizes, userid, mtime, did, title) VALUES\n\t\t\t\t\t\t\t('" . $info['name'] . "', '" . $info['ext'] . "', '" . $info['type'] . "', " . $info['filesize'] . ", '" . $info['src'] . "', " . $info['srcwidth'] . ", " . $info['srcheight'] . ", '" . $info['size'] . "', " . $info['userid'] . ", " . $info['mtime'] . ", " . $did . ", '" . $file . "')"); } nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['upload_createimage'], $path . '/' . $file, $admin_info['userid']); echo $file; exit;
/** * Back-end create thumbs * Upload function **/ function creatThumb($file, $dir, $width, $height = 0) { $image = new NukeViet\Files\Image($file, NV_MAX_WIDTH, NV_MAX_HEIGHT); if (empty($height)) { $image->resizeXY($width, NV_MAX_HEIGHT); } else { if ($width * $image->fileinfo['height'] / $image->fileinfo['width'] > $height) { $image->resizeXY($width, NV_MAX_HEIGHT); } else { $image->resizeXY(NV_MAX_WIDTH, $height); } $image->cropFromCenter($width, $height); } // Kiem tra anh ton tai $fileName = $width . 'x' . $height . '-' . basename($file); $fileName2 = $fileName; $i = 1; while (file_exists($dir . '/' . $fileName2)) { $fileName2 = preg_replace('/(.*)(\\.[a-zA-Z0-9]+)$/', '\\1-' . $i . '\\2', $fileName); ++$i; } $fileName = $fileName2; // Luu anh $image->save($dir, $fileName); $image->close(); return substr($image->create_Image_info['src'], strlen($dir . '/')); }
$upload = new NukeViet\Files\Upload(array('images'), $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT); // Storage in temp dir $upload_info = $upload->save_file($_FILES['image_file'], NV_ROOTDIR . '/' . NV_TEMP_DIR, false); // Delete upload tmp @unlink($_FILES['image_file']['tmp_name']); if (empty($upload_info['error'])) { $basename = $upload_info['basename']; $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . nv_genpass(8) . "_" . $user_info['userid'] . '\\2', $basename); $image = new NukeViet\Files\Image($upload_info['name'], NV_MAX_WIDTH, NV_MAX_HEIGHT); // Resize image, crop image $image->resizeXY($array['w'], $array['h']); $image->cropFromLeft($array['x1'], $array['y1'], $array['avatar_width'], $array['avatar_height']); $image->resizeXY($global_config['avatar_width'], $global_config['avatar_height']); // Save new image $image->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename); $image->close(); if (file_exists($image->create_Image_info['src'])) { $array['filename'] = str_replace(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/', '', $image->create_Image_info['src']); if ($array['u'] == "upd") { updateAvatar($array['filename']); $array['success'] = 2; } elseif ($array['u'] == "src") { updateAvatar($array['filename']); $array['filename'] = NV_BASE_SITEURL . SYSTEM_UPLOADS_DIR . '/' . $module_upload . '/' . $array['filename']; $array['success'] = 3; } else { $array['success'] = 1; } } else { $array['error'] = $lang_module['avatar_error_save']; }
/** * nv_get_viewImage() * * @param mixed $fileName * @return */ function nv_get_viewImage($fileName) { global $array_thumb_config; if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png|bmp|ico)))$/i', $fileName, $m)) { $viewFile = NV_FILES_DIR . '/' . $m[1]; if (file_exists(NV_ROOTDIR . '/' . $viewFile)) { $size = @getimagesize(NV_ROOTDIR . '/' . $viewFile); return array($viewFile, $size[0], $size[1]); } else { $m[2] = rtrim($m[2], '/'); if (isset($array_thumb_config[NV_UPLOADS_DIR . '/' . $m[2]])) { $thumb_config = $array_thumb_config[NV_UPLOADS_DIR . '/' . $m[2]]; } else { $thumb_config = $array_thumb_config['']; $_arr_path = explode('/', NV_UPLOADS_DIR . '/' . $m[2]); while (sizeof($_arr_path) > 1) { array_pop($_arr_path); $_path = implode('/', $_arr_path); if (isset($array_thumb_config[$_path])) { $thumb_config = $array_thumb_config[$_path]; break; } } } $viewDir = NV_FILES_DIR; if (!empty($m[2])) { if (!is_dir(NV_ROOTDIR . '/' . $m[2])) { $e = explode('/', $m[2]); $cp = NV_FILES_DIR; foreach ($e as $p) { if (is_dir(NV_ROOTDIR . '/' . $cp . '/' . $p)) { $viewDir .= '/' . $p; } else { $mk = nv_mkdir(NV_ROOTDIR . '/' . $cp, $p); if ($mk[0] > 0) { $viewDir .= '/' . $p; } } $cp .= '/' . $p; } } } $image = new NukeViet\Files\Image(NV_ROOTDIR . '/' . $fileName, NV_MAX_WIDTH, NV_MAX_HEIGHT); if ($thumb_config['thumb_type'] == 4) { $thumb_width = $thumb_config['thumb_width']; $thumb_height = $thumb_config['thumb_height']; $maxwh = max($thumb_width, $thumb_height); if ($image->fileinfo['width'] > $image->fileinfo['height']) { $thumb_config['thumb_width'] = 0; $thumb_config['thumb_height'] = $maxwh; } else { $thumb_config['thumb_width'] = $maxwh; $thumb_config['thumb_height'] = 0; } } if ($image->fileinfo['width'] > $thumb_config['thumb_width'] or $image->fileinfo['height'] > $thumb_config['thumb_height']) { $image->resizeXY($thumb_config['thumb_width'], $thumb_config['thumb_height']); if ($thumb_config['thumb_type'] == 4) { $image->cropFromCenter($thumb_width, $thumb_height); } $image->save(NV_ROOTDIR . '/' . $viewDir, $m[3] . $m[4], $thumb_config['thumb_quality']); $create_Image_info = $image->create_Image_info; $error = $image->error; $image->close(); if (empty($error)) { return array($viewDir . '/' . basename($create_Image_info['src']), $create_Image_info['width'], $create_Image_info['height']); } } elseif (copy(NV_ROOTDIR . '/' . $fileName, NV_ROOTDIR . '/' . $viewDir . '/' . $m[3] . $m[4])) { $return = array($viewDir . '/' . $m[3] . $m[4], $image->fileinfo['width'], $image->fileinfo['height']); $image->close(); return $return; } else { return false; } } } else { $size = @getimagesize(NV_ROOTDIR . '/' . $fileName); return array($fileName, $size[0], $size[1]); } return false; }