dpwu16132 2019-07-06 05:41
浏览 349
已采纳

fopen($ filename,“a +”)和file_put_contents($ filename,= $ data.PHP_EOL,FILE_APPEND)似乎附加到文件

Trying to append file with either:

file_put_contents($filename, "
" . $barcode_number.PHP_EOL, FILE_APPEND);

or

$myfile = fopen($filename, 'a+');

neither appending my file. Both are over writing old information
Things I have tried are in code comments

    $myfile = fopen($filename, 'a+') or die("unable to open file" . $filename);

    $barcode_number = $_POST['SBN'];
    //$newLine = PHP_EOL; 
    //echo  $temp.$barcode_number; die();

    fwrite($myfile, $barcode_number.PHP_EOL);
    fwrite($myfile, "
");

    //file_put_contents($filename, "
" . $barcode_number.PHP_EOL, FILE_APPEND);
    fclose($myfile);
    //echo "wrote " . $barcode_number . "to " . $filename; die();

Expected output is:

123456
123457
123458

actual output is:

123458
  • 写回答

1条回答 默认 最新

  • donglu7286 2019-07-06 06:35
    关注

    Your file_put_contents() call is formatted correctly, although I don't think you need the .PHP_EOL, since you're already prepending the data with " ". So is your fopen()/fwrite()/fclose(). Is it possible that another script is opening this file, and thus locking the file?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?