$tempFile = $_FILES['Filedata']['tmp_name']; $targetFile = $directory . '/' . $_FILES['Filedata']['name']; // Validate the file size (Warning: the largest files supported by this code is 2GB) $file_size = filesize($tempFile); if (!$file_size || $file_size > PGRFileManagerConfig::$fileMaxSize) { exit(0); } //check file ext if (PGRFileManagerConfig::$allowedExtensions != "") { if (preg_match('/^.*\\.(' . PGRFileManagerConfig::$allowedExtensions . ')$/', strtolower($_FILES['Filedata']['name'])) === 0) { exit(0); } } move_uploaded_file($tempFile, $targetFile); //if image check size, and rescale if necessary try { if (preg_match('/^.*\\.(jpg|gif|jpeg|png|bmp)$/', strtolower($_FILES['Filedata']['name'])) > 0) { $targetFile = realpath($targetFile); $imageInfo = PGRFileManagerUtils::getImageInfo($targetFile); if ($imageInfo !== false && ($imageInfo['height'] > PGRFileManagerConfig::$imageMaxHeight || $imageInfo['width'] > PGRFileManagerConfig::$imageMaxWidth)) { require_once realpath(dirname(__FILE__) . '/../PGRThumb/php/Image.php'); $image = PGRThumb_Image::factory($targetFile); $image->maxSize(PGRFileManagerConfig::$imageMaxWidth, PGRFileManagerConfig::$imageMaxHeight); $image->saveImage($targetFile, 80); } } } catch (Exception $e) { //todo } } exit(0);
} //check file ext if (PGRFileManagerConfig::$allowedExtensions != "") { if (preg_match('/^.*\\.(' . PGRFileManagerConfig::$allowedExtensions . ')$/', strtolower($elem)) === 0) { continue; } } $filepath = $directory . '/' . $elem; if (is_file($filepath)) { $file = array(); $file['filename'] = $elem; $file['shortname'] = strlen($elem) > 17 ? substr($elem, 0, 17) . '...' : $elem; $file['size'] = PGRFileManagerUtils::formatBytes(filesize($filepath)); $file['md5'] = md5(filemtime($filepath)); if (PGRFileManagerConfig::$ckEditorExtensions != "") { $file['ckEdit'] = preg_match('/^.*\\.(' . PGRFileManagerConfig::$ckEditorExtensions . ')$/', strtolower($elem)) > 0; } else { $file['ckEdit'] = false; } $file['date'] = date('Y-m-d H:i:s', filemtime($filepath)); $file['imageInfo'] = PGRFileManagerUtils::getImageInfo($filepath); if ($file['imageInfo'] != false) { $file['thumb'] = PGRFileManagerUtils::getPhpThumb("src=" . urlencode(PGRFileManagerConfig::$rootPath . $_POST['dir'] . '/' . $elem) . "&w=64&h=64&md5=" . $file['md5']); } else { $file['thumb'] = false; } $files[] = $file; } } echo json_encode(array('res' => 'OK', 'files' => $files)); exit(0);