douzhong8856 2012-09-04 16:54
浏览 100

如何在php的文件开头写入数据? [重复]

Possible Duplicate:
Need to write at beginning of file with PHP

I am trying to make a log file. But I want to insert data at beginning of file. I have read many solutions but many of them given following solution.

-> Open file in append mode.
-> Copy whole data in a variable.
-> concatenate data with temp variable.
-> Rewrite whole file.

I have visit and read following link. Need to write at beginning of file with PHP

I think this process is time consuming if my log file is around 50 to 85 MB.

Is there any that i can move file pointer at beginning of file and then just insert data save that file ?

I need some optimized way that it can work for me.

  • 写回答

2条回答 默认 最新

  • duanca3415 2012-09-04 16:57
    关注

    No, you can't stick new data at the beginning of a file. Your choices are:

    1. open new file, write new data, then append old file to new file
    2. open original file, copy old data "down" farther into the file, then overwrite the start of the file.

    Any reason you need to log things at the start of your file? It's trivial to read only the last part of a file.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程