Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Path help for program.
Old 06-23-2009, 07:30 AM Path help for program.
Average Talker

Posts: 26
Trades: 0
Now i have a small problem with my program, what it is to do is to search through all my directories and read each file and put them in to a database word by word so a search engine can be used to search each file. On my machine it works absolutely perfectly, however when moved to another it doesnt work as the path is different for where to search.

Is there anyway to make the program automatically find the right path if you understand what i mean. Here is a snippet of my code that i know the problem lies in

PHP Code:
function opening($file)
{
$stoplist "H:/xampplite/htdocs/worksheets/stoplist.txt";
$pattern "(\.txt$)| (\.php$)| (\.html$)| (\.htm$)";
if(
eregi($pattern$file)){
 
$file_handle fopen($file"r");
 
$contents file($file);
 while (!
feof($file_handle)){
  
$data fgets($file_handle);
  
$words explode(' ' $data);
  
$duplicates array_unique($words);
  
sort($duplicates);
  if(
is_bool(strpos($stoplist'$duplicates[i]')))
  {
  foreach(
$duplicates as $word)
  {
   
$word serialize($word);
   
$sql "INSERT INTO webdata VALUES('$file','$word')";
   if (
mysql_query($sql))
   {
    print 
"successful <p>";
   }
  }
  }

}
}
else {
echo 
"Cant open that file type <p>"; }
}
 
function 
getfiles($dirname=".")
{
$pattern "(\.txt$)| (\.php$)| (\.htm$)| (\.html$)";
$file = array($file);
if(
$handle opendir($dirname)) {
 while(
false !== ($file readdir($handle))){
  if(
eregi($pattern$file) || is_dir($file))
  echo 
"$file <br />";
  
opening($file);
 
}
closedir($handle);
}
return(
$file);
}

getfiles("..");
getfiles("H:/xampplite/htdocs/worksheets"); //where need help 
thanks in advance
applebiz89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-23-2009, 08:17 AM Re: Path help for program.
akratellio's Avatar
Experienced Talker

Posts: 30
Location: Berlin Germany Europe World
Trades: 0
hi applebiz89,

you can get the path while using __FILE__ and than there are functions like
dirname(), basedir() etc to verify you needs. hope they help.
Btw. there is a function called scandir()...

mfg akratellio
__________________
I'm always lying...
Ich lüge immer...

Please login or register to view this content. Registration is FREE
akratellio is offline
Reply With Quote
View Public Profile Visit akratellio's homepage!
 
Old 06-23-2009, 08:47 AM Re: Path help for program.
Average Talker

Posts: 26
Trades: 0
I'm not quite sure how to use these, and base name doesnt that just give the last name of a given paths so 'xampp/htdocs/autospider.php' for example would just bring back autospider? I want to it to automatically find the path that the file is running from and search the directory which it is held rather than manually entering a new path everytime change computers
applebiz89 is offline
Reply With Quote
View Public Profile
 
Old 06-23-2009, 10:01 AM Re: Path help for program.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
change
PHP Code:
$stoplist "H:/xampplite/htdocs/worksheets/stoplist.txt"
to
PHP Code:
$stoplist $_SERVER['DOCUMENT_ROOT']."/worksheets/stoplist.txt"
and
PHP Code:
getfiles("H:/xampplite/htdocs/worksheets"
to
PHP Code:
getfiles($_SERVER['DOCUMENT_ROOT']."/worksheets"
This will instruct PHP not to look in a specific directory, but to base the search into the root directory of your website.
Then, expand from there.
I often put uploaded files or sqlite db outside the htdocs realm, and use this code to reach them:
PHP Code:
$sqliteRoot=$_SERVER['DOCUMENT_ROOT']."/../sqlite/";
$fileUpRoot=$_SERVER['DOCUMENT_ROOT']."/../upload/"
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-24-2009, 06:40 AM Re: Path help for program.
akratellio's Avatar
Experienced Talker

Posts: 30
Location: Berlin Germany Europe World
Trades: 0
hi,

just use

Code:
$absPath = __FILE__;
$relPath = "../../{$absPath}";
the $relPath represents the path from your current path...

mfg akratellio
__________________
I'm always lying...
Ich lüge immer...

Please login or register to view this content. Registration is FREE
akratellio is offline
Reply With Quote
View Public Profile Visit akratellio's homepage!
 
Reply     « Reply to Path help for program.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.54576 seconds with 12 queries