如何在 js 文件上使用 fopen/fwrite?
我正在尝试执行此操作
$fp = fopen('all.js', 'w');
fwrite($fp, 'sddddddddddddddddddddd');
echo "<script src=\"/inc/all.js\" type=\"text/javascript\"></script>";
,但文件始终为空...您可以在 js 文件上使用 fwrite 并写入它...我检查了权限,一切都很好...有什么想法吗?
I am trying to do this
$fp = fopen('all.js', 'w');
fwrite($fp, 'sddddddddddddddddddddd');
echo "<script src=\"/inc/all.js\" type=\"text/javascript\"></script>";
but the file is always empty...can you use fwrite on a js file and write to it...i checked permissions and all is good there...any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
fwrite 不在乎你是否正在编写文本、js、php 或原始二进制垃圾。它只是输出你告诉它的内容。
问题是您正在写入
all.js
,但在脚本标记中引用/inc/all.js
。除非脚本的当前工作目录设置为 URL/inc
映射到服务器上的任何目录,否则您将在一个位置写入,但从另一个位置读取。fwrite couldn't care less if you're writing text, js, php, or raw binary garbage. It just outputs what you tell it to.
The problem is that you're writing out to
all.js
, but are refering to/inc/all.js
in your script tag. Unless your script's current-working-directory is set to whatever directory the URL/inc
maps to on your server, you're writing in one place, but reading from another.