我确实在文件test.php
中创建了一个函数。当我直接打开文件时,该功能正在运行。但是当我在wordpress标头中包含文件时,出现以下错误:
Fatal error: Uncaught Error: Call to a member function getDirectories() on null in /home/vdouser/domains/mytriplef.nl/public_html/test.php:48 Stack trace: #0 /home/vdouser/domains/mytriplef.nl/public_html/test.php(227): addFolders() #1 /home/vdouser/domains/mytriplef.nl/public_html/wp-content/themes/mytriplef/header.php(3): require_once('/home/vdouser/d...') #2 /home/vdouser/domains/mytriplef.nl/public_html/wp-includes/template.php(730): require_once('/home/vdouser/d...') #3 /home/vdouser/domains/mytriplef.nl/public_html/wp-includes/template.php(676): load_template('/home/vdouser/d...', true, Array) #4 /home/vdouser/domains/mytriplef.nl/public_html/wp-includes/general-template.php(48): locate_template(Array, true, true, Array) #5 /home/vdouser/domains/mytriplef.nl/public_html/wp-content/themes/mytriplef/front-page.php(1): get_header() #6 /home/vdouser/domains/mytriplef.nl/public_html/wp-includes/template-loader.php(106): include('/home/vdouser/d...') #7 /home/vdouser/domains/mytriplef.nl/public_html/wp-blog-header.php(19) in /home/vdouser/domains/mytriplef.nl/public_html/test.php on line 48
/public_html/wp-content/themes/mytriplef/header.php
代码:
<?php
require_once("test.php");
/public_html/test.php
代码:
<?php
require($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$servername = "localhost";
$username = "x";
$password = "x";
$database = "x";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
require_once "vendor/autoload.php";
use MicrosoftAzure\Storage\File\FileRestProxy;
$accountName = "x";
$accountKey = "x";
$shareName = "uploadmytriplef/MyTripleF/Inkomend";
$connectionString = "DefaultEndpointsProtocol=https;AccountName=$accountName;AccountKey=$accountKey";
$fileClient = FileRestProxy::createFileService($connectionString);
$sas = 'st=2020-09-22T08%3A45%3A26Z&se=2088-07-16T08%3A45%3A00Z&sp=rl&sv=2018-03-28&sr=s&sig=ANWMpYimZlvEM4qDVuDpljy%2B4KNHT%2BC47qtvrsDlXno%3D';
$list = $fileClient->listDirectoriesAndFiles($shareName);
$azureFoldersArray = array();
function addFolders() {
global $shareName;
global $list;
global $fileClient;
global $accountName;
global $sas;
global $azureFoldersArray;
// FOLDERS
foreach($list->getDirectories() as $folders) {
$folderName = $folders->getName();
$shareName = "uploadmytriplef/MyTripleF/Inkomend/".$folderName."";
$list = $fileClient->listDirectoriesAndFiles($shareName);
// CREATE FOLDER
$shareName = "uploadmytriplef/MyTripleF/Inkomend/$folderName";
if (!file_exists("azure_storage/".$folderName."")) {
mkdir("azure_storage/".$folderName."", 0777, true);
}
array_push($azureFoldersArray, $folderName);
addFiles($folderName, $shareName);
global $conn;
$sql = "INSERT INTO mytriplef_folders (name) VALUES ('$folderName')";
if ($conn->query($sql) === TRUE) {
} else {
}
};
checkFolders();
}
有人知道为什么当我将功能包含在header.php
中时功能不起作用,但是当我直接访问test.php
文件时却起作用了
谢谢!
答案 0 :(得分:0)
将test.php
文件放入包含该文件的文件所在的目录,即[...]..../mytriplef/
,这显然是您的主题文件夹。这样,您使用的文件路径(即不带任何目录的文件路径)将是正确的。