Prestashop,PHP,无法创建和保存纯文本文件
Prestashop, PHP, cannot create and save plain text file
好的。我对 Prestashop 很困惑。我的代码如下所示:
private static function _saveToFile($vouchers = array())
{
$file = fopen(__DIR__ . 'codes.txt', 'a');
foreach ($vouchers as $voucher)
{
fwrite($file, $voucher->code . "\r\n");
}
fclose($file);
}
并被这样称呼:
Voucher::_saveToFile($vouchers);
我看到一个简单的 fopen、fwrite、fclose 情况,但在服务器上找不到该文件。我尝试了 fopen(__DIR__ . 'codes.txt', 'a')
、fopen('codes.txt', 'a')
。我将标志设置为 'w'
和 'a'
。一切都会产生相同的结果:根本没有文件。
我确定程序会得到这段代码,因为当我在 fopen()ing
之前执行 d($file)
时,它会死掉并告诉我 $file 有资源对象。
有什么我遗漏的吗?
我非常确定路径在 __DIR__
和 'codes.txt'
之间缺少斜杠
好的。我对 Prestashop 很困惑。我的代码如下所示:
private static function _saveToFile($vouchers = array())
{
$file = fopen(__DIR__ . 'codes.txt', 'a');
foreach ($vouchers as $voucher)
{
fwrite($file, $voucher->code . "\r\n");
}
fclose($file);
}
并被这样称呼:
Voucher::_saveToFile($vouchers);
我看到一个简单的 fopen、fwrite、fclose 情况,但在服务器上找不到该文件。我尝试了 fopen(__DIR__ . 'codes.txt', 'a')
、fopen('codes.txt', 'a')
。我将标志设置为 'w'
和 'a'
。一切都会产生相同的结果:根本没有文件。
我确定程序会得到这段代码,因为当我在 fopen()ing
之前执行 d($file)
时,它会死掉并告诉我 $file 有资源对象。
有什么我遗漏的吗?
我非常确定路径在 __DIR__
和 'codes.txt'