Jump to content

Store all filenames starting with ___ and ending with .log from folder in array


Recommended Posts

Hello,

First: I am new to PHPFreaks. This is my first post and it's complicated. I hope someone can help me.

 

I am creating a search system without SQL, because SQL seems not to respond on my server. It is a search for people. Users make their own profile with all their information stored in two files in the main directory of my server. If I put it in folders, the right to write and read is gone.(? Another server problem ?) Everything in folders is 403 Forbidden.

All users get two files: ___username.log and ___username_.log

___username.log contains information that was filled in in a form, each details is on another line. ___username_.log contains the description of the person, entered by himself. This can be multiple lines, so this is another file. The only HTML file on my server is the home file, which starts with an IFRAME with home.php

search.php should store all filenames in the folder starting with ___ in an array, and then search all files for the search query. All files ending with _.log should be called after the normal .log, so the searcher doesn't get two persons below each other. All files that do not contain all searched words, should be removed from the array.

 

Does anyone know how to do this?

 

 

Thanks already, Masterens

 

 

PS: If I made languagemistakes, sorry, I am not English/American

 

PS2: This is my search.php for now. I realised that it is not going to work:

 

<?php

if ($handle = opendir('.')) {

    while (false !== ($file = readdir($handle))) {

        if ($file != "." && $file != "..") {

            echo "$file\n";

        }

else

{

echo 'Er ging iets fout bij het zoeken'; }

    }

    closedir($handle);

}

else

{

echo 'Er ging iets fout bij het opvragen van details bij de database';

}

?>

glob supports wild cards and file matching patterns, You'll find it simple to implement. The following code may not work without tweeking, but it seems simple:

 

$username = glob($path.'___*.log');
$userinfo = glob($path.'___*_.log');

You can append array searches to $username and $userinfo arrays for your keyword exclusions.

Thank you, oni-kun, I will look at it soon. I have this for now

<?php

if ($handle = opendir('')) {

    echo "Zoekresultaten:\n";

 

    /* This is the correct way to loop over the directory. */

    while (false !== ($file = readdir($handle))) {

        echo "$file\n";

    }

$numboffiles=count($file)

$fileshad=0;

while ($fileshad <= $numboffiles) {

$check=0;

$check=substr_count($file[$fileshad],"___");

if ($check >= 1) {

$userfiles[$fileshad] = $file[$fileshad];

}

$fileshad++

 

}

 

?>

but wouldnt the first line with glob also find the second line? i mean

* can be $path."example".'.log'

* can also be $path."example_".'.log'

the first line would also find the second

or can I just do something like

$username -= $userinfo

 

 

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.