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;
$ext = nv_getextension($file); $newname = $newname . '.' . $ext; if ($file != $newname) { $newname2 = $newname; $i = 1; while (file_exists(NV_ROOTDIR . '/' . $path . '/' . $newname2)) { $newname2 = preg_replace('/(.*)(\\.[a-zA-Z0-9]+)$/', '\\1_' . $i . '\\2', $newname); ++$i; } $newname = $newname2; if (!@rename(NV_ROOTDIR . '/' . $path . '/' . $file, NV_ROOTDIR . '/' . $path . '/' . $newname)) { die('ERROR_' . $lang_module['errorNotRenameFile']); } if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png|bmp)))$/i', $path . '/' . $file, $m)) { @nv_deletefile(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $m[1]); } if (isset($array_dirname[$path])) { $info = nv_getFileInfo($path, $newname); $sth = $db->prepare("UPDATE " . NV_UPLOAD_GLOBALTABLE . "_file SET name = '" . $info['name'] . "', src = '" . $info['src'] . "', title = '" . $newname . "', alt = :newalt WHERE did = " . $array_dirname[$path] . " AND title = '" . $file . "'"); $sth->bindParam(':newalt', $newalt, PDO::PARAM_STR); $sth->execute(); } nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['rename'], $path . '/' . $file . ' -> ' . $path . '/' . $newname, $admin_info['userid']); } else { $sth = $db->prepare("UPDATE " . NV_UPLOAD_GLOBALTABLE . "_file SET alt = :newalt WHERE did = " . $array_dirname[$path] . " AND title = '" . $file . "'"); $sth->bindParam(':newalt', $newalt, PDO::PARAM_STR); $sth->execute(); nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['rename'], $path . '/' . $file . ' -> ' . $path . '/' . $newname, $admin_info['userid']); } echo $newname; exit;
$createImage->save(NV_ROOTDIR . '/' . $path, $upload_info['basename'], $thumb_config['thumb_quality']); } } } } } } $editor = $nv_Request->get_title('editor', 'post,get', ''); $CKEditorFuncNum = $nv_Request->get_int('CKEditorFuncNum', 'post,get', 0); if (!preg_match("/^([a-zA-Z0-9\\-\\_]+)\$/", $editor)) { $editor = ''; } if (empty($error)) { if (isset($array_dirname[$path])) { $did = $array_dirname[$path]; $info = nv_getFileInfo($path, $upload_info['basename']); $info['userid'] = $admin_info['userid']; $newalt = $nv_Request->get_title('filealt', 'post', '', true); if (empty($newalt)) { $newalt = preg_replace('/(.*)(\\.[a-zA-Z0-9]+)$/', '\\1', $upload_info['basename']); $newalt = str_replace('-', ' ', change_alias($newalt)); } $sth = $db->prepare("INSERT INTO " . NV_UPLOAD_GLOBALTABLE . "_file\n\t\t(name, ext, type, filesize, src, srcwidth, srcheight, sizes, userid, mtime, did, title, alt) VALUES\n\t\t('" . $info['name'] . "', '" . $info['ext'] . "', '" . $info['type'] . "', " . $info['filesize'] . ", '" . $info['src'] . "', " . $info['srcwidth'] . ", " . $info['srcheight'] . ", '" . $info['size'] . "', " . $info['userid'] . ", " . $info['mtime'] . ", " . $did . ", '" . $upload_info['basename'] . "', :newalt)"); $sth->bindParam(':newalt', $newalt, PDO::PARAM_STR); $sth->execute(); } nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['upload_file'], $path . '/' . $upload_info['basename'], $admin_info['userid']); if ($editor == 'ckeditor') { echo "<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction(" . $CKEditorFuncNum . ", '" . NV_BASE_SITEURL . $path . "/" . $upload_info['basename'] . "', '');</script>"; } else { echo $upload_info['basename'];
$moved_images = array(); foreach ($images as $image) { $i = 1; $file = $image; // Change file name if exists while (file_exists(NV_ROOTDIR . '/' . $newfolder . '/' . $file)) { $file = preg_replace('/(.*)(\\.[a-zA-Z0-9]+)$/', '\\1_' . $i . '\\2', $image); ++$i; } $moved_images[] = $file; if (!nv_copyfile(NV_ROOTDIR . '/' . $path . '/' . $image, NV_ROOTDIR . '/' . $newfolder . '/' . $file)) { die("ERROR#" . $lang_module['errorNotCopyFile']); } if (isset($array_dirname[$newfolder])) { $did = $array_dirname[$newfolder]; $info = nv_getFileInfo($newfolder, $file); $info['userid'] = $admin_info['userid']; $db->query("INSERT INTO " . NV_UPLOAD_GLOBALTABLE . "_file (name, ext, type, filesize, src, srcwidth, srcheight, sizes, userid, mtime, did, title) VALUES ('" . $info['name'] . "', '" . $info['ext'] . "', '" . $info['type'] . "', " . $info['filesize'] . ", '" . $info['src'] . "', " . $info['srcwidth'] . ", " . $info['srcheight'] . ", '" . $info['size'] . "', " . $info['userid'] . ", " . $info['mtime'] . ", " . $did . ", '" . $file . "')"); } if (!$mirror) { @nv_deletefile(NV_ROOTDIR . '/' . $path . '/' . $image); // Delete old thumb if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png|bmp)))$/i', $path . '/' . $image, $m)) { @nv_deletefile(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $m[1]); } if (isset($array_dirname[$path])) { $did = $array_dirname[$path]; $db->query("DELETE FROM " . NV_UPLOAD_GLOBALTABLE . "_file WHERE did = " . $did . " AND title='" . $image . "'"); } } nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['move'], $path . '/' . $image . " -> " . $newfolder . '/' . $file, $admin_info['userid']);
/** * nv_filesList() * * @param mixed $pathimg * @param bool $refresh * @param string $newFile * @return */ function nv_filesList($pathimg, $refresh, $newFile = "", $delFile = "") { global $array_hidefolders, $admin_info; $md5 = md5($pathimg); $tempFile = NV_ROOTDIR . "/" . NV_FILES_DIR . "/dcache/" . $md5; $file_exists = file_exists($tempFile); $results = array(); if ($file_exists) { $results = file_get_contents($tempFile); $results = unserialize($results); } else { $refresh = true; } if (is_dir(NV_ROOTDIR . "/" . $pathimg)) { if ($refresh) { if ($dh = opendir(NV_ROOTDIR . "/" . $pathimg)) { $files = array(); while (($file = readdir($dh)) !== false) { if (in_array($file, $array_hidefolders)) { continue; } if (preg_match("/([a-zA-Z0-9\\.\\-\\_\\s\\(\\)]+)\\.([a-zA-Z0-9]+)\$/", $file)) { $files[] = $file; $info = nv_getFileInfo($pathimg, $file); if (!empty($newFile) and $file == $newFile) { $info[8] = $admin_info['userid']; $info[9] = NV_CURRENTTIME; } else { if (isset($results[$file][8])) { $info[8] = $results[$file][8]; } if (isset($results[$file][9])) { $info[9] = $results[$file][9]; } } $results[$file] = $info; } } closedir($dh); $files = array_flip($files); $results = array_intersect_key($results, $files); } ksort($results); file_put_contents($tempFile, serialize($results)); } else { if (!empty($newFile)) { $info = nv_getFileInfo($pathimg, $newFile); $info[8] = $admin_info['userid']; $info[9] = NV_CURRENTTIME; $results[$newFile] = $info; ksort($results); file_put_contents($tempFile, serialize($results)); } if (!empty($delFile)) { unset($results[$delFile]); file_put_contents($tempFile, serialize($results)); } } } return $results; }
/** * nv_filesListRefresh() * * @param mixed $pathimg * @return */ function nv_filesListRefresh($pathimg) { global $array_hidefolders, $admin_info, $db_config, $module_data, $db, $array_dirname; $results = array(); $did = $array_dirname[$pathimg]; if (is_dir(NV_ROOTDIR . '/' . $pathimg)) { $result = $db->query('SELECT * FROM ' . NV_UPLOAD_GLOBALTABLE . '_file WHERE did = ' . $did); while ($row = $result->fetch()) { $results[$row['title']] = $row; } if ($dh = opendir(NV_ROOTDIR . '/' . $pathimg)) { while (($title = readdir($dh)) !== false) { if (in_array($title, $array_hidefolders)) { continue; } if (preg_match('/([a-zA-Z0-9\\.\\-\\_\\s\\(\\)]+)\\.([a-zA-Z0-9]+)$/', $title, $m)) { $info = nv_getFileInfo($pathimg, $title); $info['did'] = $did; $info['title'] = $title; $info['sizes'] = $info['size']; unset($info['size']); if (isset($results[$title])) { $info['userid'] = $results[$title]['userid']; $dif = array_diff_assoc($info, $results[$title]); if (!empty($dif)) { // Cập nhật CSDL file thay đổi $db->query("UPDATE " . NV_UPLOAD_GLOBALTABLE . "_file SET filesize=" . intval($info['filesize']) . ", src='" . $info['src'] . "', srcwidth=" . intval($info['srcwidth']) . ", srcheight=" . intval($info['srcheight']) . ", sizes='" . $info['sizes'] . "', userid=" . $admin_info['userid'] . ", mtime=" . $info['mtime'] . " WHERE did = " . $did . " AND title = " . $db->quote($title)); } unset($results[$title]); } else { $info['userid'] = $admin_info['userid']; $newalt = preg_replace('/(.*)(\\.[a-zA-Z0-9]+)$/', '\\1', $title); $newalt = str_replace('-', ' ', change_alias($newalt)); // Thêm file mới $sth = $db->prepare("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, alt)\n\t\t\t\t\t\t\tVALUES (:name, '" . $info['ext'] . "', '" . $info['type'] . "', " . intval($info['filesize']) . ", '" . $info['src'] . "', " . intval($info['srcwidth']) . ", " . intval($info['srcheight']) . ", '" . $info['sizes'] . "', " . $info['userid'] . ", " . $info['mtime'] . ", " . $did . ", :title, :newalt)"); $sth->bindParam(':name', $info['name'], PDO::PARAM_STR); $sth->bindParam(':title', $title, PDO::PARAM_STR); $sth->bindParam(':newalt', $newalt, PDO::PARAM_STR); $sth->execute(); } } } closedir($dh); if (!empty($results)) { // Xóa CSDL file không còn tồn tại foreach ($results as $title => $value) { $db->query("DELETE FROM " . NV_UPLOAD_GLOBALTABLE . "_file WHERE did = " . $did . " AND title=" . $db->quote($title)); } } $db->query('UPDATE ' . NV_UPLOAD_GLOBALTABLE . '_dir SET time = ' . NV_CURRENTTIME . ' WHERE did = ' . $did); } } else { // Xóa CSDL thư mục không còn tồn tại $db->query('DELETE FROM ' . NV_UPLOAD_GLOBALTABLE . '_file WHERE did = ' . $did); $db->query('DELETE FROM ' . NV_UPLOAD_GLOBALTABLE . '_dir WHERE did = ' . $did); } }