0
私は、FTPサーバーからWordPressのショートコードでファイルを取得しようとしています。FTPサーバーからファイルの内容を取得する - WordPress
WPショートコードの作成を開始する前に、自分のコードを「空白」、つまりWP以外の環境に書き込んでテストしましたが、正常に動作していました。
次に、コードをWPショートコードに移動しました。そして今私は問題があります。
まず、私はあなたが....ワードプレスで()
をのfile_get_contentsを使用することができないことを学んだ...だから、私は()wp_remote_getとその機能を置き換えます。しかし、この関数は 'ftp://'で始まるURLを受け付けません。ここで
が私のコードで、変更する必要があるもの上の任意のアイデアは、私はwp_remote_get()と()のfile_get_contentsを交換するとき、それは$stuff = array();
$conn_id = ftp_connect($ftp_server) or die("Error: Cannot connect to FTP Server.");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "";
} else {
echo "Error: Cannot connect to FTP Server.";
}
if (($response_xml_data = file_get_contents('ftp://username:[email protected]/file.xml'))===false){
echo "Error: Failed to fetch file.<br/>";
} else {
libxml_use_internal_errors(true);
print_r($response_xml_data);
$data = simplexml_load_string($response_xml_data);
if (!$data) {
echo "Error loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
} else {
$stuff = $data;
}
}
// close the connection
ftp_close($conn_id);
?:ワードプレスで働いてもらうために、$のresponse_xml_dataは等しい:
WP_Error Object ([errors] => Array ([http_request_failed] => Array ([0] => A valid URL was not provided.)) [error_data] => Array ())