[GH-ISSUE #869] problem with advanced search (find nothing) #580

Closed
opened 2026-03-02 15:59:57 +03:00 by kerem · 21 comments
Owner

Originally created by @robdi123 on GitHub (Oct 17, 2022).
Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/869

root search works excelent but advanced search brings nothings and i have an error on the console related to de JSON.

error tiny

i hope someone can help me. thanks.

Originally created by @robdi123 on GitHub (Oct 17, 2022). Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/869 root search works excelent but advanced search brings nothings and i have an error on the console related to de JSON. ![error tiny](https://user-images.githubusercontent.com/42899303/196167367-3f20d229-22a8-4060-8154-8dd116c94212.jpg) i hope someone can help me. thanks.
kerem closed this issue 2026-03-02 15:59:57 +03:00
Author
Owner

@rizrmd commented on GitHub (Nov 5, 2022):

I think the problem lies here:

github.com/prasathmani/tinyfilemanager@2c0e6d216e/tinyfilemanager.php (L3023)

Somehow RegexIterator is not picking up right file for searches.

<!-- gh-comment-id:1304373293 --> @rizrmd commented on GitHub (Nov 5, 2022): I think the problem lies here: https://github.com/prasathmani/tinyfilemanager/blob/2c0e6d216ec96ac2057d90c9f3ffaff9ad173080/tinyfilemanager.php#L3023 Somehow RegexIterator is not picking up right file for searches.
Author
Owner

@rizrmd commented on GitHub (Nov 5, 2022):

Naah.

This is the problem: ajax searches is being preceded by another ajax request and never executed, so the solution is just to move ajax search to the top

<!-- gh-comment-id:1304375169 --> @rizrmd commented on GitHub (Nov 5, 2022): Naah. This is the problem: ajax searches is being preceded by another ajax request and never executed, so the solution is just to move ajax search to the top
Author
Owner

@robdi123 commented on GitHub (Nov 7, 2022):

hi, thanks for the answer. so you mean i should move the fm_search function to the top?

<!-- gh-comment-id:1305491087 --> @robdi123 commented on GitHub (Nov 7, 2022): hi, thanks for the answer. so you mean i should move the fm_search function to the top?
Author
Owner

@rizrmd commented on GitHub (Nov 7, 2022):

I mean, add this:


if (isset($_POST['ajax'])) {
    //search : get list of files from the current folder
    if(isset($_POST['type']) && $_POST['type']=="search") {
        $dir = FM_ROOT_PATH;
        $response = scan(fm_clean_path($_POST['path']), $_POST['content']);
        echo json_encode($response);
        exit();
    }
}

before this:

github.com/prasathmani/tinyfilemanager@2c0e6d216e/tinyfilemanager.php (L426)

That should fix this issue. I'm sorry for putting it right here instead of proper pull request.

<!-- gh-comment-id:1305499909 --> @rizrmd commented on GitHub (Nov 7, 2022): I mean, add this: ``` if (isset($_POST['ajax'])) { //search : get list of files from the current folder if(isset($_POST['type']) && $_POST['type']=="search") { $dir = FM_ROOT_PATH; $response = scan(fm_clean_path($_POST['path']), $_POST['content']); echo json_encode($response); exit(); } } ``` before this: https://github.com/prasathmani/tinyfilemanager/blob/2c0e6d216ec96ac2057d90c9f3ffaff9ad173080/tinyfilemanager.php#L426 That should fix this issue. I'm sorry for putting it right here instead of proper pull request.
Author
Owner

@rizrmd commented on GitHub (Nov 7, 2022):

I just created ad-hoc pull request https://github.com/prasathmani/tinyfilemanager/pull/878

<!-- gh-comment-id:1305502970 --> @rizrmd commented on GitHub (Nov 7, 2022): I just created ad-hoc pull request https://github.com/prasathmani/tinyfilemanager/pull/878
Author
Owner

@robdi123 commented on GitHub (Nov 7, 2022):

now i have error 500... sorry i have no experience with ajax.
Captura de pantalla 2022-11-07 093608

<!-- gh-comment-id:1305548923 --> @robdi123 commented on GitHub (Nov 7, 2022): now i have error 500... sorry i have no experience with ajax. ![Captura de pantalla 2022-11-07 093608](https://user-images.githubusercontent.com/42899303/200312649-ee926cf0-1fa7-4865-bcfa-2f3189140682.jpg)
Author
Owner

@rizrmd commented on GitHub (Nov 7, 2022):

Can you show response body of that 500 error ? You can open network tab, click item that has red color (500 error) and show the body

<!-- gh-comment-id:1305702910 --> @rizrmd commented on GitHub (Nov 7, 2022): Can you show response body of that 500 error ? You can open network tab, click item that has red color (500 error) and show the body
Author
Owner

@robdi123 commented on GitHub (Nov 7, 2022):

is this?

response 1-2
response 2-2

Thanks.

<!-- gh-comment-id:1305725703 --> @robdi123 commented on GitHub (Nov 7, 2022): is this? ![response 1-2](https://user-images.githubusercontent.com/42899303/200339528-58c6c5c5-3ddf-4611-9506-488fec8e9f61.jpg) ![response 2-2](https://user-images.githubusercontent.com/42899303/200339545-d779eee0-bf26-4b00-ac28-8017db2beb4a.jpg) Thanks.
Author
Owner

@rizrmd commented on GitHub (Nov 7, 2022):

is this?

response 1-2 response 2-2

Thanks.

Sorry, I mean request and response body, not the header. After you click that, make sure to screenshot "Request" and "Response" Tab

<!-- gh-comment-id:1306336133 --> @rizrmd commented on GitHub (Nov 7, 2022): > is this? > > ![response 1-2](https://user-images.githubusercontent.com/42899303/200339528-58c6c5c5-3ddf-4611-9506-488fec8e9f61.jpg) ![response 2-2](https://user-images.githubusercontent.com/42899303/200339545-d779eee0-bf26-4b00-ac28-8017db2beb4a.jpg) > > Thanks. Sorry, I mean request and response body, not the header. After you click that, make sure to screenshot "Request" and "Response" Tab
Author
Owner

@robdi123 commented on GitHub (Nov 8, 2022):

as response it show my header

response1
response2
response3

i cant find the request tab

tab

Thanks!

<!-- gh-comment-id:1307106626 --> @robdi123 commented on GitHub (Nov 8, 2022): as response it show my header ![response1](https://user-images.githubusercontent.com/42899303/200559870-20efb45c-2150-4cd0-9db7-a0fa11568feb.jpg) ![response2](https://user-images.githubusercontent.com/42899303/200559877-fd32bec5-3e23-4144-961d-33b5ed3fe01d.jpg) ![response3](https://user-images.githubusercontent.com/42899303/200559878-b03cdb31-cc1e-431a-a678-ed5c9b521ddf.jpg) i cant find the request tab ![tab](https://user-images.githubusercontent.com/42899303/200560038-e627c8b0-4dd1-4a6b-a879-f2904a20769f.jpg) Thanks!
Author
Owner

@rizrmd commented on GitHub (Nov 8, 2022):

I mean Payload

<!-- gh-comment-id:1307113017 --> @rizrmd commented on GitHub (Nov 8, 2022): I mean Payload
Author
Owner

@robdi123 commented on GitHub (Nov 8, 2022):

pay

😄

<!-- gh-comment-id:1307115783 --> @robdi123 commented on GitHub (Nov 8, 2022): ![pay](https://user-images.githubusercontent.com/42899303/200560956-96571c0f-2d4f-4e51-bcdf-10c75f71799f.jpg) 😄
Author
Owner

@rizrmd commented on GitHub (Nov 8, 2022):

I mean, add this:


if (isset($_POST['ajax'])) {
    //search : get list of files from the current folder
    if(isset($_POST['type']) && $_POST['type']=="search") {
        $dir = FM_ROOT_PATH;
        $response = scan(fm_clean_path($_POST['path']), $_POST['content']);
        echo json_encode($response);
        exit();
    }
}

before this:

github.com/prasathmani/tinyfilemanager@2c0e6d216e/tinyfilemanager.php (L426)

That should fix this issue. I'm sorry for putting it right here instead of proper pull request.

Are you sure have done this ?
because it looks like your request just somehow skipped this line:

if (isset($_POST['ajax'])) {
     //search : get list of files from the current folder
     if(isset($_POST['type']) && $_POST['type']=="search") {

If you check in payload, we have $_POST['ajax'] and $_POST['type'] set to "search", It should work.
Maybe replace your tinyfilemanager.php with latest one from master branch.

<!-- gh-comment-id:1307124469 --> @rizrmd commented on GitHub (Nov 8, 2022): > I mean, add this: > > ``` > > if (isset($_POST['ajax'])) { > //search : get list of files from the current folder > if(isset($_POST['type']) && $_POST['type']=="search") { > $dir = FM_ROOT_PATH; > $response = scan(fm_clean_path($_POST['path']), $_POST['content']); > echo json_encode($response); > exit(); > } > } > ``` > > before this: > > https://github.com/prasathmani/tinyfilemanager/blob/2c0e6d216ec96ac2057d90c9f3ffaff9ad173080/tinyfilemanager.php#L426 > > That should fix this issue. I'm sorry for putting it right here instead of proper pull request. Are you sure have done this ? because it looks like your request just somehow skipped this line: ``` if (isset($_POST['ajax'])) { //search : get list of files from the current folder if(isset($_POST['type']) && $_POST['type']=="search") { ``` If you check in payload, we have $_POST['ajax'] and $_POST['type'] set to "search", It should work. Maybe replace your tinyfilemanager.php with [latest one from master branch](https://github.com/prasathmani/tinyfilemanager/blob/master/tinyfilemanager.php).
Author
Owner

@robdi123 commented on GitHub (Nov 8, 2022):

yes, i did that.
ajax

yesterday i compare the lastest file with mine one and thers not to many changes, all the changes are basically made by me (i modify the login, some icons, not to much)

<!-- gh-comment-id:1307133244 --> @robdi123 commented on GitHub (Nov 8, 2022): yes, i did that. ![ajax](https://user-images.githubusercontent.com/42899303/200562835-2f1d239a-8a9b-4b18-8d89-9db7e97851e6.jpg) yesterday i compare the lastest file with mine one and thers not to many changes, all the changes are basically made by me (i modify the login, some icons, not to much)
Author
Owner

@rizrmd commented on GitHub (Nov 8, 2022):

That's weird, I need to do some debugging. If you are available, I'm willing to help you with live coding session. It's convenient to use pop - maybe install it first on your desktop and then create a session with me.

<!-- gh-comment-id:1307268972 --> @rizrmd commented on GitHub (Nov 8, 2022): That's weird, I need to do some debugging. If you are available, I'm willing to help you with live coding session. It's convenient to use [pop](https://pop.com) - maybe install it first on your desktop and then create a session with me.
Author
Owner

@robdi123 commented on GitHub (Nov 8, 2022):

when can you help me? and how we can do it? i have the production site on my computer to.

<!-- gh-comment-id:1307293661 --> @robdi123 commented on GitHub (Nov 8, 2022): when can you help me? and how we can do it? i have the production site on my computer to.
Author
Owner

@rizrmd commented on GitHub (Nov 8, 2022):

Okay, after we do our live session. It's concluded that tinyfilemanager cannot be "injected" to view or controller inside your framework. Because somehow $_POST is being modified and tinyfilemanager cannot see $_POST['ajax'] nor $_POST['type'].

So you should directly visit tinyfilemanager.php or embed it using

<!-- gh-comment-id:1307329989 --> @rizrmd commented on GitHub (Nov 8, 2022): Okay, after we do our live session. It's concluded that tinyfilemanager cannot be "injected" to view or controller inside your framework. Because somehow $_POST is being modified and tinyfilemanager cannot see $_POST['ajax'] nor $_POST['type']. So you should directly visit tinyfilemanager.php or embed it using <iframe />
Author
Owner

@robdi123 commented on GitHub (Nov 14, 2022):

@rizrmd Hi, i made it work with a controller, and advanced search work if i go in a folder, but it doesnt work on root 😮‍💨...

i think something here <a class="dropdown-item" href="<?php echo $path2 = $path ? $path : '.'; ?> is not working for me, do you have any idea of what can be wrong?

Tnaks in advanc.

<!-- gh-comment-id:1313930039 --> @robdi123 commented on GitHub (Nov 14, 2022): @rizrmd Hi, i made it work with a controller, and advanced search work if i go in a folder, but it doesnt work on root 😮‍💨... i think something here `<a class="dropdown-item" href="<?php echo $path2 = $path ? $path : '.'; ?>` is not working for me, do you have any idea of what can be wrong? Tnaks in advanc.
Author
Owner

@AwaisHaider1 commented on GitHub (Nov 28, 2022):

@rizrmd Hi, i made it work with a controller, and advanced search work if i go in a folder, but it doesnt work on root 😮‍💨...

i think something here <a class="dropdown-item" href="<?php echo $path2 = $path ? $path : '.'; ?> is not working for me, do you have any idea of what can be wrong?

Tnaks in advanc.

@robdi123 For advanced search to work also in the root folder just remove the condition in scan function.

function scan($dir, $filter = '') {
    $path = FM_ROOT_PATH.'/'.$dir;
    $ite = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
    $rii = new RegexIterator($ite, "/(" . $filter . ")/i");

    $files = array();
    foreach ($rii as $file) {
        if (!$file->isDir()) {
            $fileName = $file->getFilename();
            $location = str_replace(FM_ROOT_PATH, '', $file->getPath());
            $files[] = array(
                "name" => $fileName,
                "type" => "file",
                "path" => $location,
            );
        }
    }
    return $files;
}
<!-- gh-comment-id:1328785163 --> @AwaisHaider1 commented on GitHub (Nov 28, 2022): > @rizrmd Hi, i made it work with a controller, and advanced search work if i go in a folder, but it doesnt work on root 😮‍💨... > > i think something here `<a class="dropdown-item" href="<?php echo $path2 = $path ? $path : '.'; ?>` is not working for me, do you have any idea of what can be wrong? > > Tnaks in advanc. @robdi123 For advanced search to work also in the root folder just remove the condition in scan function. ``` function scan($dir, $filter = '') { $path = FM_ROOT_PATH.'/'.$dir; $ite = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); $rii = new RegexIterator($ite, "/(" . $filter . ")/i"); $files = array(); foreach ($rii as $file) { if (!$file->isDir()) { $fileName = $file->getFilename(); $location = str_replace(FM_ROOT_PATH, '', $file->getPath()); $files[] = array( "name" => $fileName, "type" => "file", "path" => $location, ); } } return $files; } ```
Author
Owner

@prasathmani commented on GitHub (Nov 28, 2022):

@AwaisHaider1 thanks for the answer, it is already fixed in latest version.

<!-- gh-comment-id:1328810530 --> @prasathmani commented on GitHub (Nov 28, 2022): @AwaisHaider1 thanks for the answer, it is already fixed in latest version.
Author
Owner

@robdi123 commented on GitHub (Dec 16, 2022):

@rizrmd Hi, i made it work with a controller, and advanced search work if i go in a folder, but it doesnt work on root 😮‍💨...
i think something here <a class="dropdown-item" href="<?php echo $path2 = $path ? $path : '.'; ?> is not working for me, do you have any idea of what can be wrong?
Tnaks in advanc.

@robdi123 For advanced search to work also in the root folder just remove the condition in scan function.

function scan($dir, $filter = '') {
    $path = FM_ROOT_PATH.'/'.$dir;
    $ite = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
    $rii = new RegexIterator($ite, "/(" . $filter . ")/i");

    $files = array();
    foreach ($rii as $file) {
        if (!$file->isDir()) {
            $fileName = $file->getFilename();
            $location = str_replace(FM_ROOT_PATH, '', $file->getPath());
            $files[] = array(
                "name" => $fileName,
                "type" => "file",
                "path" => $location,
            );
        }
    }
    return $files;
}

Thanks!!! it works!

<!-- gh-comment-id:1355326088 --> @robdi123 commented on GitHub (Dec 16, 2022): > > @rizrmd Hi, i made it work with a controller, and advanced search work if i go in a folder, but it doesnt work on root 😮‍💨... > > i think something here `<a class="dropdown-item" href="<?php echo $path2 = $path ? $path : '.'; ?>` is not working for me, do you have any idea of what can be wrong? > > Tnaks in advanc. > > @robdi123 For advanced search to work also in the root folder just remove the condition in scan function. > > ``` > function scan($dir, $filter = '') { > $path = FM_ROOT_PATH.'/'.$dir; > $ite = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); > $rii = new RegexIterator($ite, "/(" . $filter . ")/i"); > > $files = array(); > foreach ($rii as $file) { > if (!$file->isDir()) { > $fileName = $file->getFilename(); > $location = str_replace(FM_ROOT_PATH, '', $file->getPath()); > $files[] = array( > "name" => $fileName, > "type" => "file", > "path" => $location, > ); > } > } > return $files; > } > ``` Thanks!!! it works!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tinyfilemanager#580
No description provided.