【发布时间】:2019-12-06 11:28:45
【问题描述】:
大家好,这是我的代码。
function markenbuero_csv() {
// open the file "demosaved.csv" for writing
$file = fopen('demosaved.csv', 'w');
// save the column headers
fputcsv($file, array('Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5'));
// Sample data. This can be fetched from mysql too
$data = array(
array('Data 11', 'Data 12', 'Data 13', 'Data 14', 'Data 15'),
array('Data 21', 'Data 22', 'Data 23', 'Data 24', 'Data 25'),
array('Data 31', 'Data 32', 'Data 33', 'Data 34', 'Data 35'),
array('Data 41', 'Data 42', 'Data 43', 'Data 44', 'Data 45'),
array('Data 51', 'Data 52', 'Data 53', 'Data 54', 'Data 55')
);
// save each row of the data
foreach ($data as $row)
{
fputcsv($file, $row);
}
// Close the file
fclose($file);
echo 'worked';
}
我通过我的 Wordpress 自定义插件页面中的表单调用它,它会呼应“工作”,但不会在我的插件文件夹中创建文件。 表单如下所示:
<form style="margin-top:50px" action="#" method="post">
<input type="submit" name="a_submit" value="CSV laden">
</form>
我叫它的方式:
if(isset($_POST['a_submit'])){
markenbuero_csv();
}
我不确定我错过了什么。感谢您帮助我。
【问题讨论】:
-
“但不在我的插件文件夹中创建文件。” - 这可能是因为您只指定了文件名。此代码可能位于您的插件文件中,但这并不意味着它也是嵌入和运行您的插件代码的主脚本实例的工作目录。 stackoverflow.com/questions/20780422/…