Page 1 of 1

Help with a search.php modifying

Posted: Tue Feb 25, 2025 4:23 pm
by Toxdale
Hi, I am not a professional but sometimes manage PHP scripts on an elementary level. I have a problem with a small search.php. I have a folder with PDF documents and the search.php is in this folder. It finds documents by file name and displays them with a link to the document. The files have applicants' names and once you enter the name of an applicant it opens the link to the PDF file. However, I want the script (search.php) to do dual job:
1. to find and link to 'approved' files as it does now,
2. to open another website when finding 'disapproved' files.
For example, if the file name is "john-dow-approved.pdf" the script will link to this file. But if the file name is "john-dow-disapproved.pdf" the script will link to or open another website.
Here is the script below:
-----------------
<?php

$dirname = "./";//Directory to search in. *Must have a trailing slash*
$findme = $_POST["search"];

$dir = opendir($dirname);

while(false != ($file = readdir($dir))){//Loop for every item in the directory.
if(($file != ".") and ($file != "..") and ($file != ".DS_Store") and ($file != "search.php"))//Exclude these files from the search
{
$pos = stripos($file, $findme);
if ($pos !== false){
$thereisafile = true;//Tell the script something was found.
echo'<a href="' . $dirname . $file . '">' . $file . '</a><br>';//Display the search results as links.
}else{
//Leave this blank
}
}
}
if (!isset($thereisafile)){
echo "No records match your criteria.";//Tell the user nothing was found.
echo '<img src="">';//Display an image, when nothing was found.
}
?>
-----------------------------

Thank you for your kind support

Re: Help with a search.php modifying

Posted: Tue Feb 25, 2025 7:43 pm
by Klemen
Hi,

This forum is meant to support the phpjunkyard.com scripts, not general PHP help.

I will keep your question up, but I wouldn't expect a helpful answer. You may want to find other places where people help with general PHP scripts.