I need help with a search.php script

Toxdale

New member
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
 
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
The script only checks if the search term is present in the filename and does not account for the suffixes that indicate approval status.
You need to modify the script to include conditional checks for the suffixes "approved" and "disapproved" in the filenames. If a file is approved, it will link to the file; if disapproved, it will redirect to a specified external website.
 
Back
Top