Jump to content

Warning: strpos(): Empty needle in SearchScript.php on line 7


tobimichigan
Go to solution Solved by davidannis,

Recommended Posts

Im having this error being thrown up on execution donno what could be wrong. Actually Im trying to display specific files as a url link for download from a search box. Could some1 tell me how I can get over this error?

<?php
$dir = 'dir for search'; 
$exclude = array('.','..','.htaccess'); 
$q = (isset($_GET['q']))? strtolower($_GET['q']) : ''; 
$res = opendir($dir); 
while(false!== ($file = readdir($res))) { 
if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) { 
echo "<a href='$dir/$file'>$file</a>"; 
echo "<br>"; 
} 
} 
closedir($res); 
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>SEARCH SCRIPT</title>
</head>

<body>
<div id='header'>
SEARCH FOR FILES
</div>
<div id='formsearch'>
<form action='SearchScript.php' method='get'><input name='q'
type='text'> <input type='submit'></form>
</div>
<div>
</body>
</html>

the line 7 => 

 if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) { 

what is wrong with this line? Any ideas?

Link to comment
Share on other sites

One more thing David, on my local machine the dir is C:\xampp\htdocs\ASearch,

 

ie 

$dir = 'dir for search';

the code executes properly, but on my subdomain say http://s.hgf.com, where the target files are when I click the submit button, the browser just keeps loading and does not respond. Meanwhile the local 1 executes properly. How do you think I should link up to the subdomain in order for this script to work?

Link to comment
Share on other sites

You'd need to setup $dir to be equal to whatever file-system (ie, not http: something) path you want to scan. If you do this with a relative path, or by creating a path using php's magic constants then you can probably use the same value both locally and remotely. Otherwise you'd need to check which server you're on using $_SERVER['HTTP_HOST'] or similar and set the variable accordingly

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.