Home
'); // Avoid write javascript in the files $link = str_replace($no_symbol, "", $link); $name = str_replace($no_symbol, "", $name); // Get the last occurrence of '.' and the remaining text $lastDotIndex = strrpos($link, "."); if ($lastDotIndex) { $filetype = substr($link, $lastDotIndex + 1); } else { $filetype = "others"; } $filetype = str_replace('.', "", $filetype); $filetype = strtolower($filetype); if(!file_exists("categories")){ mkdir("categories"); } if(!file_exists("categories/$category")){ mkdir("categories/$category"); } if (isset($_POST['submit'])) { if(!file_exists("categories/$category/$name")){ $file = fopen("categories/$category/$name", "w"); fwrite($file, $link); fclose($file); $result = "
Sent with success!"; } else { $result = "
File already exists!"; } } $start = $_GET['start']; if (!$start){$start = 0;} $search = $_POST['search']; if ($search == ""){$search = $_GET['search'];} // Avoid accessing the above directories //$search = str_replace('.', "", $search); if ($search == ""){$search = '.';} $c = 0; $limit = 20; $ini = $start * $limit; $end = $ini + $limit; $entry = 0; $collum = 0; $search = strtolower($search); echo "
$result
"; if ($search != "" ){ $dir = 'categories'; // Open the directory if ($handle = opendir($dir)) { // Loop through each subdirectory while (false !== ($subdir = readdir($handle))) { if ($subdir != "." && $subdir != ".." && is_dir($dir.'/'.$subdir)) { // Open the subdirectory if ($subhandle = opendir($dir.'/'.$subdir)) { // Loop through each file in the subdirectory while (false !== ($file = readdir($subhandle))) { $filename_written = $file; // Find the occurrence in lower or uppercase $file_l = strtolower($file); //if ($subdir == $search){echo 'ok';} // Check if the filename contains the string // If there is a category with the searched name all the files within that category will be displayed if (strpos($file_l, $search) !== false || $subdir == $search) { // Pagination if($entry >= $ini and $entry < $end){ if ($file == "." || $file == ".."){continue;} $file_path = $dir.'/'.$subdir.'/'.$file; // Get size of the file $filesize = filesize($file_path); // Checks if is a binary file or small text content if($filesize > 500){ $contents = $file_path; } else { $contents = file_get_contents($file_path); } // For get the last dot in the filename $lastDotIndex = strrpos($contents, "."); if ($lastDotIndex) { $filetype = substr($contents, $lastDotIndex + 1); $filetype = strtolower($filetype); // Don't show characters or variables after the file extension $filetype = substr($filetype, 0, 3); } else{ $filetype = "none"; } $display_name = $filename_written; $name_len = strlen($filename_written); // Cut string if name is long if ($name_len > 40){ $display_name = substr($display_name, 0, 40) . "..."; } $img = ""; // Show case be a picture extension if($filetype == "png" || $filetype == "jpg" || $filetype == "jpeg" || $filetype == "gif"){ $img = ""; } // Show a thumbnail case exists if(file_exists('thumbs/' . $subdir . '/' . $filename_written . '.jpg')){ $img = ""; } // Toggle table colors // Show in the end the contents that don't are pictures (for don't break the pictures flow the 'continue' is used) if ($img == ""){$toggle++; $td_color = $toggle % 2 == 0 ? '#FFF' : '#EEE'; $text_result = $text_result . "";$search_break++; continue;} // Align and format content in three columns if($collum == 0){echo "";} echo $img; $collum++; if($collum == 3){echo ""; $collum = 0;} $search_break++; } $entry++; // Skip the files of the directory when reached the total results if($search_break == $end){break;} } } if($search_break == $end){break;} // Close the subdirectory closedir($subhandle); } } } // Close the directory closedir($handle); } if ($search_break == 0){ echo "
Not found."; } } echo "

$display_name
Comment

$display_name
Comment
  $filename_written$subdir$filetypeComment
"; echo "
$text_result
"; if (!$search && !$start && !$result){ echo "Hello!"; } echo "

"; if ($entry){ for ($i = $start; $i < $start + 20; $i++) { echo "$i "; } } echo "
"; ?>