所以我在从 AJAX 请求调用的 PHP 页面上包含一个文件时遇到了问题:
$(document).ready(function() {
$("#image-status").html('Processing images...');
});
function process_images(files) {
$.ajax ({
type: "POST",
url: "includes/imageprocessor.php",
data: {files: JSON.stringify(files)},
success: function(data){
$("#image-status").html(data);
}
});
}
我在 imageprocessor.php 上尝试这个 require_once:
require_once("db_connect.php");
它也在包含目录中,并且有效:我只是在另一个页面上使用它来运行一个工作正常的插入。但是当我尝试运行时:
function get_files($id) {
$query = $db->prepare("SELECT * FROM files INNER JOIN file_profile_join ON files.id = file_profile_join.file_id WHERE file_profile_join.profile_id = " . $id . " GROUP BY files.id");
try {
$query->execute();
$rows = $query->fetch();
} catch (PDOException $e) {
die($e->getMessage());
}
}
稍后在 imageprocessor.php 中,它会出错:
Fatal error: Call to a member function prepare() on a non-object in /home/yogabopvolume26/theprivatesector.org/epic/includes/imageprocessor.php on line 90
就像它首先不需要 db_connect 一样(这就是声明 $db 的地方)。但它也没有返回找不到 db_connect.php 的错误。
basename(__DIR__)
在 imageprocessor.php 上(通过 AJAX 请求回显)返回“include”。
我已经尝试在 require_once 中同时使用绝对 URL 和根路径,但它既不会出错,也不会继续使用 imageprocessor.php:在返回 require_once 后,该文件没有回显。我也无法从 session_start 获取当前会话(我可以从原始页面 [profile.php] 打印_r $_SESSION,因此会话处于活动状态)。也许他们有关系?我不知道出了什么问题。