// Check if form is submitted
if(isset($_POST['submit'])) {
// Get URL and search string from form
$url = $_POST['url'];
$searchString = $_POST['searchString'];
// Get all files in parent URL and child folders
$files = glob($url . '/**/*.*', GLOB_BRACE);
// Initialize array to store matching files
$matchingFiles = array();
// Loop through files and search for search string
foreach($files as $file) {
// Check if file is a directory
if(is_dir($file)) {
continue;
}
// Read file contents
$fileContents = file_get_contents($file);
// Check if file contents contain search string
if(strpos($fileContents, $searchString) !== false) {
// Add file to matching files array
$matchingFiles[] = $file;
}
}
// Display matching files in table
if(count($matchingFiles) > 0) {
echo '
';
echo '| Matching Files |
';
foreach($matchingFiles as $matchingFile) {
echo '| ' . $matchingFile . ' |
';
}
echo '
';
} else {
echo 'No matching files found.';
}
}
// Check if download button is clicked
if(isset($_POST['download'])) {
// Get selected files from form
$selectedFiles = $_POST['selectedFiles'];
// Loop through selected files and download them
foreach($selectedFiles as $selectedFile) {
// Get file name
$fileName = basename($selectedFile);
// Set headers for download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($selectedFile));
// Read file and output to browser
readfile($selectedFile);
}
}
?>