function uploadImg($clib, $chkT, $selR) { global $cfg; global $l; if (!$cfg['upload']) { return false; } foreach ($_FILES['nfile']['size'] as $key => $size) { if ($size > 0) { // get file extension and check for validity $ext = pathinfo($_FILES['nfile']['name'][$key]); $ext = strtolower($ext['extension']); if (!in_array($ext, $cfg['valid'])) { // invalid image echo $l->m('er_029'); return false; } $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path $nfile = fixFileName($_FILES['nfile']['name'][$key]); // remove invalid characters in filename // move file to temp directory for processing if (!move_uploaded_file($_FILES['nfile']['tmp_name'][$key], $cfg['temp'] . '/' . $nfile)) { // upload image to temp dir echo $l->m('er_028'); return false; } $size = getimagesize($cfg['temp'] . '/' . $nfile); // process (thumbnail) images $arr = $cfg['thumbs']; foreach ($arr as $key => $thumb) { if (in_array($key, $chkT)) { // create new phpThumb() object require_once dirname(__FILE__) . '/phpThumb/phpthumb.class.php'; $phpThumb = new phpThumb(); // create object // parameters $phpThumb->config_cache_disable_warning = true; // disable cache warning $phpThumb->config_output_format = $ext; // output format $phpThumb->src = $cfg['temp'] . '/' . $nfile; // destination $phpThumb->q = 95; // compression level for jpeg if ($selR != '') { // set auto rotate $phpThumb->ar = $selR; } //------------------------------------------------------------------------- if ($thumb['size'] > 0 && ($size[0] >= $thumb['size'] || $size[1] >= $thumb['size'])) { // size value is set -> RESIZING and source image is larger than preset sizes // resize parameters if ($size[0] < $size[1]) { // portrait $phpThumb->h = $thumb['size']; // max. height } else { $phpThumb->w = $thumb['size']; // max. width } // crop parameters if ($thumb['crop'] == true) { $phpThumb->zc = 1; // set zoom crop $phpThumb->w = $thumb['size']; // width $phpThumb->h = $thumb['size']; // height } // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . $thumb['size']; // e.g. _1280 } else { if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_' . $thumb['ext']; } } //------------------------------------------------------------------------- } elseif ($thumb['size'] == 0 || $thumb['size'] == '*') { // size value is set to '0' -> NO RESIZING // crop parameters if ($thumb['crop'] == true) { $phpThumb->zc = 1; // set zoom crop if ($size[0] < $size[1]) { // portrait $phpThumb->w = $size[0]; // getimagesize width value $phpThumb->h = $size[0]; // getimagesize width value } else { // landscape $phpThumb->w = $size[1]; // getimagesize height value $phpThumb->h = $size[1]; // getimagesize height value } } // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . ($size[0] <= $size[1] ? $size[1] : $size[0]); // source height or width - e.g. _1280 } else { if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_' . $thumb['ext']; } } //------------------------------------------------------------------------- } else { // default setting - images smaller than predefined sizes $dim = ''; // no file suffix is used } //------------------------------------------------------------------------- $nthumb = fixFileName(basename($nfile, '.' . $ext) . $dim . '.' . $ext); $nthumb = chkFileName($path, $nthumb); // rename if file already exists if ($phpThumb->GenerateThumbnail()) { $phpThumb->RenderToFile($path . $nthumb); @chmod($path . $nthumb, 0755) or die($l->m('er_028')); } else { // error echo $l->m('er_028'); return false; } unset($phpThumb); } } @unlink($cfg['temp'] . '/' . $nfile); // delete temporary file } } return $nthumb; }
$phpThumb->bg = $_REQUEST['bg']; // rotate - background-color // filters $phpThumb->fltr = $_REQUEST['fltr']; // filter parameters //------------------------------------------------------------------------- // update image $tfile = pathinfo($_REQUEST['src']); $clib = $tfile['dirname'] . '/'; // current library $nfile = $tfile['basename']; // file name $ext = strtolower($tfile['extension']); // current extension $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path $nfile = fixFileName($nfile); // check file name if (!isset($_REQUEST['nfi'])) { // if not set, new file will be created, otherwise existing file will be overwritten $nfile = chkFileName($path, $nfile); // rename file if new filename already exists } //------------------------------------------------------------------------- // generate & output if ($phpThumb->GenerateThumbnail()) { if (!$phpThumb->RenderToFile($path . $nfile)) { echo 'Failed: ' . implode("\n", $phpThumb->debugmessages); } @chmod($path . $nfile, 0755) or die('chmod didn\'t work'); unset($phpThumb); // free up some memory } else { // do something with debug/error messages echo 'Failed: ' . implode("\n", $phpThumb->debugmessages); return false; }
//------------------------------------------------------------------------- // update image $tfile = pathinfo($_REQUEST['src']); $clib = $tfile['dirname'] . '/'; // current library $nfile = $tfile['basename']; // file name $ext = strtolower($tfile['extension']); // current extension $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path $nfile = fixFileName($nfile); // check file name if (!isset($_REQUEST['nfi'])) { // if not set, new file will be created, otherwise existing file will be overwritten $nfile = chkFileName($path, $nfile); // rename file if new filename already exists } //------------------------------------------------------------------------- // generate & output if ($phpThumb->GenerateThumbnail()) { if (!$phpThumb->RenderToFile($path . $nfile)) { echo 'Failed: ' . implode("\n", $phpThumb->debugmessages); } @chmod($path . $nfile, 0755) or die('chmod didn\'t work'); unset($phpThumb); // free up some memory } else { // do something with debug/error messages echo 'Failed: ' . implode("\n", $phpThumb->debugmessages); return false;
function uploadImg($clib, $chkT, $selR) { global $cfg; global $l; if (!$cfg['upload']) { return false; } foreach ($_FILES['nfile']['size'] as $key => $size) { if ($size > 0) { // get file extension and check for validity $ext = pathinfo($_FILES['nfile']['name'][$key]); $mimeType = String::mime_content_type($_FILES['nfile']['tmp_name'][0]); $ext = strtolower($ext['extension']); if (!in_array($ext, $cfg['valid'])) { // invalid image (only checks extension) echo $l->m('er_029'); return false; } if (!in_array($mimeType, $cfg['mimeTypes'])) { // invalid image (checks mime type) echo $l->m('er_029'); return false; } $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path $nfile = fixFileName($_FILES['nfile']['name'][$key]); // remove invalid characters in filename // Check that the user doesn't exceed their upload limit: $newSize = dirsize($path) + $_FILES['nfile']['size'][$key]; if ($newSize > $cfg['ulLimit'] && $cfg['ulLimit'] != 0) { echo 'Warning: Upload limit exceeded'; return false; } // move file to temp directory for processing if (!move_uploaded_file($_FILES['nfile']['tmp_name'][$key], $path . '/' . $nfile)) { // upload image to temp dir echo $l->m('er_028'); return false; } $size = getimagesize($path . '/' . $nfile); // process (thumbnail) images $arr = $cfg['thumbs']; foreach ($arr as $key => $thumb) { if (in_array($key, $chkT)) { // create new phpThumb() object require_once dirname(__FILE__) . '/phpThumb/ThumbLib.inc.php'; $phpThumb = PhpThumbFactory::create($path . '/' . $nfile); // Create object //------------------------------------------------------------------------- if ($thumb['size'] > 0 && ($size[0] >= $thumb['size'] || $size[1] >= $thumb['size'])) { // size value is set -> RESIZING and source image is larger than preset sizes // resize parameters $phpThumb->resize($thumb['size'], $thumb['size']); // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . $thumb['size']; // e.g. _1280 } else { if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_' . $thumb['ext']; } } //------------------------------------------------------------------------- } elseif ($thumb['size'] == 0 || $thumb['size'] == '*') { // size value is set to '0' -> NO RESIZING // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . ($size[0] <= $size[1] ? $size[1] : $size[0]); // source height or width - e.g. _1280 } else { if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_' . $thumb['ext']; } } //------------------------------------------------------------------------- } else { // default setting - images smaller than predefined sizes $dim = ''; // no file suffix is used } //------------------------------------------------------------------------- $nthumb = fixFileName(basename($nfile, '.' . $ext) . sanitize_filename($dim) . '.' . $ext); $nthumb = chkFileName($path, $nthumb); // rename if file already exists $phpThumb->save($path . $nthumb); @chmod($path . $nthumb, 0755) or die($l->m('er_028')); unset($phpThumb); } } @unlink($path . '/' . $nfile); // delete temporary file } } return $nthumb; }