当我直接调用PHP文件时,它会完全按照我的预期生成一个文本文件。但是当我使用AJAX时,它不会生成文本文件。
我对目录和文件chmod(0777)
进行了说明,并将allow_url_fopen
设置为“ ON”。
我确定AJAX正在调用indexing.php
,但没有创建文本文件。
怎么了?
$('#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);
?>