The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.

Search for files without MySQL... - Guest

  • 15th March 2023 06:36:42 PM
  • PHP
  • 4622 views
  1. <?php error_reporting(0); ?>
  2.  
  3. <html>
  4.   <head>
  5.     <style>
  6.  
  7.       body {
  8.         font-family: Arial;
  9.       }
  10.                
  11.       .main {
  12.         padding: 5px;        
  13.       }        
  14.      
  15.       td {
  16.         padding-left: 10px;    
  17.       }
  18.  
  19.     </style>
  20.   </head>
  21.  
  22.   <body>
  23.     <table class='main' width='100%'>
  24.       <tr>
  25.         <td>
  26.           <form action="index.php" method="POST">
  27.             <input type="text" placeholder="Insert a link or URL" name="link">
  28.             <input type="text" placeholder="Name" name="name">
  29.             <input type="text" placeholder="Category" name="category">
  30.             <input type="submit" name="submit">
  31.             &nbsp; <a href='index.php'>Home</a>
  32.           </form>
  33.         </td>
  34.         <td>
  35.           <div align='right'>
  36.             <form action="index.php" method="POST">
  37.               <input type="text" placeholder="Search" name="search">
  38.               <input type="submit" value="Search">    
  39.             </form>
  40.           </div>
  41.         </td>
  42.       </tr>
  43.     </table>
  44.  
  45. <?php
  46.  
  47. $link = $_POST['link'];
  48. $name = $_POST['name'];
  49. $category = $_POST['category'];
  50.  
  51. if(!$name){
  52.     $name = preg_replace('/[^a-zA-Z0-9]/', ' ', $link);
  53. }
  54.  
  55. if(!$category){
  56.     $category = "others";
  57. }
  58.  
  59. // Avoid write files in not allowed directories
  60. $name = str_replace('.', "", $name);
  61. $category = str_replace('.', "", $category);
  62.  
  63. $category = strtolower($category);
  64.  
  65. $no_symbol = array ('<', '>');
  66.  
  67. // Avoid write javascript in the files
  68. $link = str_replace($no_symbol, "", $link);
  69. $name = str_replace($no_symbol, "", $name);
  70.  
  71. // Get the last occurrence of '.' and the remaining text
  72. $lastDotIndex = strrpos($link, ".");
  73.  
  74. if ($lastDotIndex) {
  75.  
  76.     $filetype = substr($link, $lastDotIndex + 1);
  77.  
  78. } else {
  79.  
  80.     $filetype = "others";
  81.  
  82. }
  83.  
  84. $filetype = str_replace('.', "", $filetype);
  85. $filetype = strtolower($filetype);
  86.  
  87. if(!file_exists("categories")){
  88.     mkdir("categories");
  89. }
  90.  
  91. if(!file_exists("categories/$category")){
  92.     mkdir("categories/$category");
  93. }
  94.  
  95. if (isset($_POST['submit'])) {
  96.     if(!file_exists("categories/$category/$name")){
  97.         $file = fopen("categories/$category/$name", "w");
  98.         fwrite($file, $link);
  99.         fclose($file);
  100.         $result = "<br><a href='categories/$category/$name' target='_blank'>Sent with success!</a>";
  101.  
  102.     } else {
  103.        
  104.         $result = "<br>File already exists!";
  105.     }
  106. }
  107.  
  108. $start = $_GET['start'];  
  109.        
  110. if (!$start){$start = 0;}
  111.  
  112. $search = $_POST['search'];
  113.  
  114. if ($search == ""){$search = $_GET['search'];} 
  115.  
  116. // Avoid accessing the above directories
  117. $search = str_replace('.', "", $search);
  118.  
  119. $c = 0;
  120. $limit = 20;
  121. $ini = $start *  $limit;
  122. $end = $ini + $limit;
  123.  
  124. $entry = 0;
  125.  
  126. $search = strtolower($search);
  127.  
  128. echo "<hr>$result <table width='100%'>";
  129.  
  130. if ($search != "" ){
  131.  
  132.     $dir = 'categories';
  133.  
  134.     // Open the directory
  135.     if ($handle = opendir($dir)) {
  136.  
  137.         // Loop through each subdirectory
  138.         while (false !== ($subdir = readdir($handle))) {
  139.  
  140.             if ($subdir != "." && $subdir != ".." && is_dir($dir.'/'.$subdir)) {
  141.  
  142.                 // Open the subdirectory
  143.                 if ($subhandle = opendir($dir.'/'.$subdir)) {
  144.  
  145.                     // Loop through each file in the subdirectory
  146.                     while (false !== ($file = readdir($subhandle))) {
  147.                        
  148.                         $filename_written = $file;  
  149.  
  150.                         // Find the occurrence in lower or uppercase                    
  151.                         $file_l = strtolower($file);
  152.  
  153.                         //if ($subdir == $search){echo 'ok';}
  154.                        
  155.                         // Check if the filename contains the string
  156.                         // If there is a category with the searched name all the files within that category will be displayed
  157.                         if (strpos($file_l, $search) !== false || $subdir == $search) {
  158.  
  159.                             // Pagination
  160.                             if($entry >= $ini and $entry  < $end){
  161.                                
  162.                                 if ($file == "." || $file == ".."){continue;}
  163.  
  164.                                 // Display the filename
  165.                                 //echo $dir.'/'.$subdir.'/'.$file . "<br>";
  166.  
  167.                                 $td_color = $entry % 2 == 0 ? '#EEE' : '#FFF';
  168.  
  169.                                 $file_path = $dir.'/'.$subdir.'/'.$file;
  170.  
  171.                                 $filesize = filesize($file_path);
  172.  
  173.                                 // Checks if is a binary file or text content
  174.                                 if($filesize > 500){
  175.  
  176.                                     $contents = $file_path;
  177.  
  178.                                 } else {
  179.  
  180.                                     $contents = file_get_contents($file_path);
  181.  
  182.                                 }
  183.  
  184.                                 $lastDotIndex = strrpos($contents, ".");
  185.  
  186.                                 if ($lastDotIndex) {
  187.  
  188.                                     $filetype = substr($contents, $lastDotIndex + 1);        
  189.                                 }
  190.  
  191.                                 $filetype = strtolower($filetype);
  192.  
  193.                                 // Don't show characters or variables after the file extension
  194.                                 $filetype = substr($filetype, 0, 3);
  195.  
  196.                                 echo "<tr style='background-color: $td_color;'><td><a href='$contents' target='_blank'>$filename_written</a></td><td>$subdir</td><td>$filetype</td><td><a href='comment.php?comment_file=$file' target='_blank'>Comment</a></td>";                  
  197.  
  198.                                 // Show case be a picture extension
  199.                                 if($filetype == "png" || $filetype == "jpg" || $filetype == "jpeg" || $filetype == "gif"){
  200.  
  201.                                    echo "<td><div align='center'><a href='$contents' target='_blank'><img src='$contents' width='184px'></a></div></td>";                  
  202.                                 }
  203.  
  204.                                 // Show a thumbnail case exists
  205.                                 if(file_exists('thumbs/' . $subdir . '/' . $filename_written . '.jpg')){
  206.  
  207.                                    echo "<td><div align='center'><a href='thumbs/$subdir/$filename_written.jpg' target='_blank'><img src='thumbs/$subdir/$filename_written.jpg' width='184px'></a></div></td>";                  
  208.                                 }
  209.  
  210.                                 $search_break++;
  211.                            
  212.                             }
  213.  
  214.                             $entry++;
  215.                        
  216.                             // Skip the files of the directory when reached the total results
  217.                             if($search_break == $end){break;}
  218.                         }
  219.                    
  220.                     }
  221.  
  222.                     if($search_break == $end){break;}
  223.          
  224.                     // Close the subdirectory
  225.                     closedir($subhandle);
  226.                 }
  227.            
  228.             }
  229.  
  230.         }
  231.  
  232.         // Close the directory
  233.         closedir($handle);
  234.     }
  235.  
  236.     if ($entry == 0){
  237.         echo "<br>Not found.";
  238.     }
  239.  
  240. }
  241.  
  242. echo "</table>";
  243.  
  244. if (!$search && !$start && !$result){
  245.   echo "Hello!";
  246. }
  247.  
  248. echo "<br><br><div align='center'>";
  249.  
  250. if ($entry){
  251.     for ($i = $start; $i < $start + 20; $i++) {
  252.         echo "<a href='index.php?start=$i&search=$search'>$i </a>";
  253.     }
  254. }
  255.  
  256. echo "</div>";
  257.  
  258. ?>

Raw Paste
Recent Pastes
Whitehat SEO for tutpaste.com
  • 1 hour
  • 9
  • secs ago

Economy Landscaping Pavers
  • 5 hours
  • 10 mins
  • 44

NEXTFLY Indianapolis Web Design
  • 7 hours
  • 38 mins
  • 15

I sell wirecheck login website...
  • 1 day
  • 2 hours
  • 30 mins

Special Ops Plumbing Service &...
  • 1 day
  • 9 hours
  • 35 mins





About Us - Terms of Use