public function action($parent) { $c = $parent->config; $util = new Utility(); $info = pathinfo($_POST['name']); if (strpos($_POST['path'], '/') === 0 || strpos($_POST['path'], '../') !== false || strpos($_POST['path'], './') === 0 || strpos($_POST['url'], 'http://s3.amazonaws.com/feather') !== 0 || $_POST['name'] != $util->fix_filename($_POST['name'], $c['transliteration'], $c['convert_spaces'], $c['replace_with']) || !in_array(strtolower($info['extension']), array('jpg', 'jpeg', 'png'))) { $this->r = array('wrong data', 400); return; } $image_data = file_get_contents($_POST['url']); if ($image_data === false) { $this->r = array('Could not save image', 400); return; } //18/04/2015 add versioning for edits $version = $this->versioning($_POST['name'], $c['current_path'], $_POST['path']); $fp = fopen($c['current_path'] . $_POST['path'] . $version, "w"); fwrite($fp, $image_data); fclose($fp); $util->create_img($c['current_path'] . $_POST['path'] . $version, $c['thumbs_base_path'] . $_POST['path'] . $version, 122, 91); // TODO something with this function cause its blowing my mind $util->new_thumbnails_creation($c['current_path'] . $_POST['path'], $c['current_path'] . $_POST['path'] . $version, $version, $c['current_path'], $relative_image_creation, $relative_path_from_current_pos, $relative_image_creation_name_to_prepend, $relative_image_creation_name_to_append, $relative_image_creation_width, $relative_image_creation_height, $relative_image_creation_option, $fixed_image_creation, $fixed_path_from_filemanager, $fixed_image_creation_name_to_prepend, $fixed_image_creation_to_append, $fixed_image_creation_width, $fixed_image_creation_height, $fixed_image_creation_option); }
public function upload(Application $app, Request $req) { $config = $app['FileManager']; $util = new Utility(); $current_path = $config['current_path']; $thumbs_base_path = $config['thumbs_base_path']; $config['ext'] = array_merge($config['ext_img'], $config['ext_file'], $config['ext_misc'], $config['ext_video'], $config['ext_music']); $ext = $config['ext']; $transliteration = $config['transliteration']; $convert_spaces = $config['convert_spaces']; $replace_with = $config['replace_with']; $ext_img = $config['ext_img']; if (isset($_POST['path'])) { $storeFolder = $_POST['path']; $storeFolderThumb = $_POST['path_thumb']; } else { $storeFolder = $current_path . $_POST["fldr"]; // correct for when IE is in Compatibility mode $storeFolderThumb = $thumbs_base_path . $_POST["fldr"]; } $path_pos = strpos($storeFolder, $current_path); $thumb_pos = strpos($storeFolderThumb, $thumbs_base_path); if ($path_pos !== 0 || $thumb_pos !== 0 || strpos($storeFolderThumb, '../', strlen($thumbs_base_path)) !== FALSE || strpos($storeFolderThumb, './', strlen($thumbs_base_path)) !== FALSE || strpos($storeFolder, '../', strlen($current_path)) !== FALSE || strpos($storeFolder, './', strlen($current_path)) !== FALSE) { die('wrong path'); } $path = $storeFolder; $cycle = TRUE; $max_cycles = 50; $i = 0; while ($cycle && $i < $max_cycles) { $i++; if ($path == $current_path) { $cycle = FALSE; } if (file_exists($path . "config.php")) { require_once $path . "config.php"; $cycle = FALSE; } $path = $util->fix_dirname($path) . '/'; } if (!empty($_FILES)) { $info = pathinfo($_FILES['file']['name']); if (in_array($util->fix_strtolower($info['extension']), $ext)) { $tempFile = $_FILES['file']['tmp_name']; $targetPath = $storeFolder; $targetPathThumb = $storeFolderThumb; $_FILES['file']['name'] = $util->fix_filename($_FILES['file']['name'], $transliteration, $convert_spaces, $replace_with); // Gen. new file name if exists if (file_exists($targetPath . $_FILES['file']['name'])) { $i = 1; $info = pathinfo($_FILES['file']['name']); // append number while (file_exists($targetPath . $info['filename'] . "_" . $i . "." . $info['extension'])) { $i++; } $_FILES['file']['name'] = $info['filename'] . "_" . $i . "." . $info['extension']; } $targetFile = $targetPath . $_FILES['file']['name']; $targetFileThumb = $targetPathThumb . $_FILES['file']['name']; // check if image (and supported) if (in_array($util->fix_strtolower($info['extension']), $ext_img)) { $is_img = TRUE; } else { $is_img = FALSE; } // upload move_uploaded_file($tempFile, $targetFile); chmod($targetFile, 0755); if ($is_img) { $memory_error = FALSE; if (!$util->create_img($targetFile, $targetFileThumb, 122, 91)) { $memory_error = FALSE; } else { // TODO something with this long function baaaah... if (!$util->new_thumbnails_creation($targetPath, $targetFile, $_FILES['file']['name'], $current_path, $relative_image_creation, $relative_path_from_current_pos, $relative_image_creation_name_to_prepend, $relative_image_creation_name_to_append, $relative_image_creation_width, $relative_image_creation_height, $relative_image_creation_option, $fixed_image_creation, $fixed_path_from_filemanager, $fixed_image_creation_name_to_prepend, $fixed_image_creation_to_append, $fixed_image_creation_width, $fixed_image_creation_height, $fixed_image_creation_option)) { $memory_error = FALSE; } else { $imginfo = getimagesize($targetFile); $srcWidth = $imginfo[0]; $srcHeight = $imginfo[1]; // resize images if set if ($image_resizing) { if ($image_resizing_width == 0) { if ($image_resizing_height == 0) { $image_resizing_width = $srcWidth; $image_resizing_height = $srcHeight; } else { $image_resizing_width = $image_resizing_height * $srcWidth / $srcHeight; } } elseif ($image_resizing_height == 0) { $image_resizing_height = $image_resizing_width * $srcHeight / $srcWidth; } // new dims and create $srcWidth = $image_resizing_width; $srcHeight = $image_resizing_height; $util->create_img($targetFile, $targetFile, $image_resizing_width, $image_resizing_height, $image_resizing_mode); } //max resizing limit control $resize = FALSE; if ($image_max_width != 0 && $srcWidth > $image_max_width && $image_resizing_override === FALSE) { $resize = TRUE; $srcWidth = $image_max_width; if ($image_max_height == 0) { $srcHeight = $image_max_width * $srcHeight / $srcWidth; } } if ($image_max_height != 0 && $srcHeight > $image_max_height && $image_resizing_override === FALSE) { $resize = TRUE; $srcHeight = $image_max_height; if ($image_max_width == 0) { $srcWidth = $image_max_height * $srcWidth / $srcHeight; } } if ($resize) { $util->create_img($targetFile, $targetFile, $srcWidth, $srcHeight, $image_max_mode); } } } // not enough memory if ($memory_error) { unlink($targetFile); header('HTTP/1.1 406 Not enought Memory', TRUE, 406); exit; } } return $app->json($_FILES['file']['name'], 200); } else { header('HTTP/1.1 406 file not permitted', TRUE, 406); exit; } } else { header('HTTP/1.1 405 Bad Request', TRUE, 405); exit; } // redirect if (isset($_POST['submit'])) { $query = http_build_query(array('type' => $_POST['type'], 'lang' => $_POST['lang'], 'popup' => $_POST['popup'], 'field_id' => $_POST['field_id'], 'fldr' => $_POST['fldr'])); header("location: dialog.php?" . $query); } }
public function two($app, $files, $twigArr, $config, $subdir, $filter, $transliteration, $thumbs_path, $get_params, Utility $util, $rfm_subfolder) { $files_prevent_duplicate = array(); $html = ""; foreach ($files as $nu => $file_array) { $file = $file_array['file']; if ($file == '.' || $file == '..' || is_dir($config['current_path'] . $rfm_subfolder . $subdir . $file) || in_array($file, $config['hidden_files']) || !in_array($util->fix_strtolower($file_array['extension']), $config['ext']) || $filter != '' && $n_files > $file_number_limit_js && stripos($file, $filter) === false) { continue; } $file_path = $config['current_path'] . $rfm_subfolder . $subdir . $file; //check if file have illegal caracter $filename = substr($file, 0, '-' . (strlen($file_array['extension']) + 1)); if ($file != $util->fix_filename($file, $transliteration)) { $file1 = $util->fix_filename($file, $transliteration); $file_path1 = $this->current_path . $rfm_subfolder . $subdir . $file1; if (file_exists($file_path1)) { $i = 1; $info = pathinfo($file1); while (file_exists($this->current_path . $rfm_subfolder . $subdir . $info['filename'] . ".[" . $i . "]." . $info['extension'])) { $i++; } $file1 = $info['filename'] . ".[" . $i . "]." . $info['extension']; $file_path1 = $this->current_path . $rfm_subfolder . $subdir . $file1; } $filename = substr($file1, 0, '-' . (strlen($file_array['extension']) + 1)); rename_file($file_path, $util->fix_filename($filename, $transliteration), $transliteration); $file = $file1; $file_array['extension'] = $util->fix_filename($file_array['extension'], $transliteration); $file_path = $file_path1; } $is_img = false; $is_video = false; $is_audio = false; $show_original = false; $show_original_mini = false; $mini_src = ""; $src_thumb = ""; $extension_lower = $util->fix_strtolower($file_array['extension']); if ($extension_lower === 'svg') { //dont try mking thumb for svg file! } else { if (in_array($extension_lower, $config['ext_img'])) { $src = $this->base_url . $this->cur_dir . rawurlencode($file); $mini_src = $src_thumb = $thumbs_path . $subdir . $file; //add in thumbs folder if not exist if (!file_exists($src_thumb)) { try { if (!$util->create_img($file_path, $src_thumb, 122, 91)) { $src_thumb = $mini_src = ""; } else { $util->new_thumbnails_creation($this->current_path . $rfm_subfolder . $subdir, $file_path, $file, $this->current_path, '', '', '', '', '', '', '', $fixed_image_creation, $fixed_path_from_filemanager, $fixed_image_creation_name_to_prepend, $fixed_image_creation_to_append, $fixed_image_creation_width, $fixed_image_creation_height, $fixed_image_creation_option); } } catch (Exception $e) { $src_thumb = $mini_src = ""; } } } $is_img = true; //check if is smaller than thumb list($img_width, $img_height, $img_type, $attr) = @getimagesize($file_path); if ($img_width < 122 && $img_height < 91) { $src_thumb = $this->cur_dir . $file; //var_dump($src_thumb); $show_original = true; } if ($img_width < 45 && $img_height < 38) { $mini_src = $this->cur_dir . $rfm_subfolder . $subdir . $file; //var_dump($mini_src); //$mini_src=$this->current_path.$rfm_subfolder.$subdir.$file."sr"; $show_original_mini = true; } $twigArr['img_width'] = $img_width; $twigArr['img_height'] = $img_height; $twigArr['src'] = $src; } $is_icon_thumb = false; $is_icon_thumb_mini = false; $no_thumb = false; if ($src_thumb == "") { $no_thumb = true; if (file_exists('img/' . $config['icon_theme'] . '/' . $extension_lower . ".jpg")) { $src_thumb = 'img/' . $config['icon_theme'] . '/' . $extension_lower . ".jpg"; } else { $src_thumb = "img/" . $config['icon_theme'] . "/default.jpg"; } $is_icon_thumb = true; } if ($mini_src == "") { $is_icon_thumb_mini = false; } $class_ext = 0; if (in_array($extension_lower, $config['ext_video'])) { $class_ext = 4; $is_video = true; } elseif (in_array($extension_lower, $config['ext_img'])) { $class_ext = 2; } elseif (in_array($extension_lower, $config['ext_music'])) { $class_ext = 5; $is_audio = true; } elseif (in_array($extension_lower, $config['ext_misc'])) { $class_ext = 3; } else { $class_ext = 1; } $twigArr['class_ext'] = $class_ext; $twigArr['is_img'] = $is_img; $twigArr['is_audio'] = $is_audio; $twigArr['is_video'] = $is_video; $twigArr['is_icon_thumb'] = $is_icon_thumb; $twigArr['show_original'] = $show_original; $twigArr['src_thumb'] = $src_thumb; $twigArr['extension_lower'] = $extension_lower; $twigArr['mini_src'] = $mini_src; $twigArr['show_original_mini'] = $show_original_mini; $twigArr['is_icon_thumb_mini'] = $is_icon_thumb_mini; $twigArr['filename'] = $filename; $twigArr['nu'] = $nu; $file_prevent_rename = false; $file_prevent_delete = false; if (isset($filePermissions[$file])) { if (isset($filePermissions[$file]['prevent_duplicate']) && $filePermissions[$file]['prevent_duplicate']) { $files_prevent_duplicate[] = $file; } $file_prevent_rename = isset($filePermissions[$file]['prevent_rename']) && $filePermissions[$file]['prevent_rename']; $file_prevent_delete = isset($filePermissions[$file]['prevent_delete']) && $filePermissions[$file]['prevent_delete']; } $twigArr['files_prevent_duplicate'][] = $file; $this->files_prevent_duplicate = $twigArr['files_prevent_duplicate']; $twigArr['file_prevent_delete'] = $file_prevent_delete; $twigArr['file_prevent_rename'] = $file_prevent_rename; $twigArr['file_array'] = $file_array; $twigArr['file'] = $file; //var_dump($twigArr['subdir']); $twigArr['file_array']['makeSize'] = $util->makeSize($file_array['size']); if (!($_GET['type'] == 1 && !$is_img) && !($_GET['type'] == 3 && !$is_video && ($_GET['type'] == 3 && !$is_audio)) && $class_ext > 0) { $template = 'FileManager/two/two.html.twig'; $html = $html . $app['twig']->render($template, $twigArr); //template! } } return $html; }