Normal file search works.

$j=0; if ($handle = opendir($_SERVER['DOCUMENT_ROOT'].'/project/'.$_GET['project'])) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $fullname=getExtension($file); if ($fullname[1] == 'php') { $filenameX[$j]=$fullname[0]; $j++; } } } closedir($handle); 

}

But if I do an Ajax, that is, this script is an ajax request handler - it produces an error 500. Why? There are no other errors, checked in the lines. 500 error due to cycle

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

the ways are all true. without ajax everything works.

  • one
    I still ask, is it possible to show the code to send an ajax request? - DanielOlivo
  • esli vi pravilno ukazali cherez ajax http put k php file ui otpravili pravilniy get what you want, go to ya dumayu tto vse budet rabotat. smotrite chto vi nedoperedali - Vanya Avchyan
  • Can you add what is in the apache / php-fpm log after the ajax request, and what comes in the response body? - Arnial pm
  • banal errors are excluded. Ajax works, the answer comes. but it is this part of the script that gives error 500. and it reads the path, it sees global variables. as if it can not scan the folder! why? similar scripts work for me. and with this zapara some sort! - XStreamka

1 answer 1

Doper himself, it was a function. for some reason other functions cannot be called from under functions.

piece of code:

 $fullname=getExtension($file); 

replaced by:

 $fullname=explode(".", $file); 

and the error is gone. Who can tell why? (