Php 文件获取内容方法不使用';如果文件包含include命令,则无法工作
我有一个wordpress项目。我试图用file_get_contents获取php文件的书面内容,但出现了一个问题,因为获取文件有一个include命令,这会发出警告 我必须使用file\u get\u contents()方法,因为我使用的是另一个在线API,它与此方法一起工作强> 在我的文件中,我在service.php中使用这个文件\u get\u contents():Php 文件获取内容方法不使用';如果文件包含include命令,则无法工作,php,wordpress,include,file-get-contents,Php,Wordpress,Include,File Get Contents,我有一个wordpress项目。我试图用file_get_contents获取php文件的书面内容,但出现了一个问题,因为获取文件有一个include命令,这会发出警告 我必须使用file\u get\u contents()方法,因为我使用的是另一个在线API,它与此方法一起工作 在我的文件中,我在service.php中使用这个文件\u get\u contents(): $url = "http://localhost/davetips/sms_service.php"; $content
$url = "http://localhost/davetips/sms_service.php";
$content = file_get_contents($url);
var_dump($content);
die();
这里是“http://localhost/davetips/sms_service.php
“:
如果我注释掉include命令,就可以了
所以我不知道,我应该如何在sms_service.php中包含wp-blog-header.php
有人有好的建议吗?你确定启用了
allow\u url\u fopen
吗?是的,它在PHP ini文件中处于启用状态:)allow\u url\u fopen=on
警告与文件内容无关,你确定它确实存在吗?根据您发布的警告消息,这意味着找不到请求的文件。嘿,:)它存在。如果我在getting php文件中注释掉include命令,这个file_get_contents()方法就可以工作!!!所以文件存在!(所以,如果我注释掉include命令,它会找到这个文件;))你检查过你的服务器日志了吗?是否转到http://localhost/davetips/sms_service.php
是否通过浏览器给出错误?wp blog header.php
是否与sms_service.php
或php include路径位于同一目录中?
<?php
// Wordpress
global $wpdb;
include 'wp-blog-header.php';
echo "test";
error_reporting(E_ALL);
ini_set("display_errors", 1);
// Password constans
$option_password_text_key = 'password_storer_text';
// And more code ...
Warning: file_get_contents(`http://localhost/davetips/sms_service.php`): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /var/www/wp-tutorial/service.php