使用 PHP 即时编辑远程文件
我需要即时编辑远程文本文件,其内容目前约为 1Mb。
我尝试了几种方法,但两种方法似乎都很笨重或占用内存,我不能依赖。
从逻辑上思考我想要实现的目标是:
- FTP 到远程服务器。
- 下载文件的副本用于备份并将其存储在本地某个位置。
- 打开远程文件并添加所需的必要行。
- 根据本地服务器生成的不需要的数据数组,从远程文件中删除行。
这可能吗?
我已经成功编写了第 1 步和第 2 步的代码,但在第 3 步和第 4 步中遇到了困难。我现在的方法是使用 fgets 并返回整个字符串。实际上,我不想这样做,因为它涉及操作和重新生成整个字符串(而且它很大),然后将其重新插入远程文件中的两个标记之间。
是否无法即时操作文件中的文本行?
I have a requirement to edit a remote text file on-the-fly, the content of which currently stands at ~1Mb.
I have tried a couple of approaches and both seem to be clunky or hog memory which I can't rely on.
Thinking out logically what I'm trying to achieve is:
- FTP to a remote server.
- Download a copy of the file for backup purposes and store it somewhere locally.
- Open the remote file and add the necessary lines required.
- Remove lines from the remote file as per an array of un-required data generated from the local server.
Is this possible?
I've managed to code steps 1 and 2 but I'm having difficult with 3 and 4. The way I'm doing it now is to use fgets and return the whole string. Really, I don't want to do this as it involves manipulating and re-generating the whole string (and it's large) and then re-inserting it in between two markers in the remote file.
Is there no way of manipulating the lines of text in the file on-the-fly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您无法通过 FTP 执行第 3 步和第 4 步。它不允许操作远程文件,仅用于文件传输。
To the best of my knowledge you cannot do 3 and 4 via FTP. It does not allow manipulation of remote files, its for file transferring only.