When I call my PHP file directly, it makes a text file exactly as I expected. But when I use AJAX, it doesn't make the text file.
I gave pemissions to directory and files: chmod(0777)
and setup allow_url_fopen
as "ON".
I made sure the AJAX is calling indexing.php
, but no text files are created.
What's going wrong?
$('#btn_index').on('click', function(){
$.ajax({url: "/indexing.php", success: function(result){
alert("Indexing is finished");
}});
});
indexing.php
<?php
$fWrite = fopen(__DIR__."/indexOfFiles.txt","w+") or die('Cannot open file: ');
if ($handle = opendir('./data/pdffiles')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$wrote = fwrite($fWrite, "$entry".PHP_EOL);
}
}
}
closedir($handle);
fclose($fWrite);
$fWrite = fopen(__DIR__."/arrays.txt","w+") or die('Cannot open file: ');
$wrote = fwrite($fWrite, '{"data": []}');
fclose($fWrite);
?>