私はPHPexcelを使用して、私はExcelのファイルを読み込むためのコードPHPを持っていると私はExcelから自分のデータを表示するためにワードプレスのプラグインを作成したい。 Localhostで実行すると、完璧に動作しますが、私のサイトで動作していない場合、別のテンプレートで試してみると、ちょうど空のコンテンツがあります。ワードプレスプラグインを作成する(PHPexcel)
ここに私のコード:normaly
function find(){
?>
<form method="post" action="">
Number : <input type="text" name="number" /><button type="submit">Find</button>
</form>
<?php
if (isset($_POST['number']) {
$number = $_POST["number"];
echo $number;
}
ページの負荷、および表示$番号:
add_shortcode('show_number', 'find');
function find(){
?>
<form method="post" action="">
Number : <input type="text" name="number" /><button type="submit">Find</button>
</form>
<?php
if (isset($_POST['number']) {
$number = $_POST["number"];
require_once (plugin_dir_path(__FILE__). 'includes\classes\PHPExcel.php');
$tmpfname = (plugin_dir_path(__FILE__). 'number.xlsx');
$excelReader = PHPExcel_IOFactory::createReaderForFile($tmpfname);
$excelObj = $excelReader->load($tmpfname);
$worksheet = $excelObj->getSheet(0);
$lastRow = $worksheet->getHighestRow();
$excel_arr = $worksheet->toArray(null,true,true,true);
for ($row=1;$row <=$lastRow;$row++){
if ($excel_arr[$row]["A"] == $number) {
echo $excel_arr[$row]["A"];
break;
}
}
}
}
私はあることを読んでExcel用のコードを削除した場合。私はワードプレスプラグインの
解決をPHPexcelコードを誤用だと思う:パスに
パスを記述するために\を使用しないでください。このシンボルは、エスケープシーケンスとして解釈することもできます。代わりに '/'を使用してください。 – Havenard
Webサーバーのログファイルを調べます。表示されないエラーメッセージが表示されます。また、Havenardによれば、 '/'を使うほうが良いでしょう。私の推測では、これは問題である:あなたはローカルでWindowsを使っていますか( "\"で大丈夫でしょうか?)、あなたのサーバーにはUnixがありますか?しかし、 "\"は一重引用符で囲まれた文字列のリテラルのバックスラッシュとして扱われるため、エスケープする必要があります。 –
([debug mode](https://codex.wordpress.org/Debugging_in_WordPress) ) –