使用"file_put_content "创建和编辑文件javascript
Create and edit file javascript with "file_put_contents"?
我想用PHP创建一个file.js,但我认为在我的代码中有很多错误:
我有多维数组:
$report= array();
$report= array(array(3,6),array(4,8));
:
Array
(
[0] => Array
(
[0] => 3
[1] => 6
)
[1] => Array
(
[0] => 4
[1] => 8
)
)
设置js文件的内容类型
$header = "Content-type: text/javascript";
$dir = "outreport/";
$nomefile = "report.js";
//delete a file with same name if exists
foreach (glob($dir."*".$nomefile) as $v){
unlink($v);
}
$percorso = $dir.$nomefile;
file_put_contents($percorso, $report);
header($header);
print($report);
有两个问题:
1)启动文件时,php要求我下载相同的文件,但在javascript
2)在"outvulcani"中,它创建了文件report.js,但为空
我希望在文件"report.js"中有数组$report但是javascript代码:
var reports = [
[3,6]
[4,8]
];
劳驾,你能帮我一下吗?非常感谢!对不起,我的英语
PHP有一个将数组转换为JSON的函数。你可以把这段代码用作"灵感"。
$report = array(array(3,6),array(4,8));
$javascriptContent = json_encode($report);
// Convert to string
$javascriptContent = "var reports = ". $javascriptContent . ";'n";
file_put_contents($percorso, $javascriptContent);
"下载"的原因是标题,请删除它
相关文章:
- 如何在visualstudio中调试web api时编辑javascript文件
- 为什么spyOn"停止函数“”的所有执行;Jasmine(要求澄清Jasmine 2.2间谍文件)
- 扩展 ACE 编辑器,如何导入自定义文件
- Node.js服务器问题-已添加“/"在浏览器中查找文件时
- 在服务器上上载后自动编辑文件
- 使用AJAX传递的数据编辑XML文件-正在删除XML数据
- 如何在单击按钮时编辑文件的内容?PHP
- 如何在使用php使用jquery编辑文件后保存文件
- 用于用户编辑文件的简单模板引擎
- 我需要一个javascript/html插件,它允许我在不编辑文件的情况下发布新闻.html
- 如何通过 php 或 javascript 编辑文件(将下载)的名称
- 如何阻止用户在 HTML 文件输入控件中手动编辑文件路径
- MVC 4无法定位“;脚本"文件夹
- 当从主机编辑文件时,虚拟机中的Nodemon看不到更改
- "文件“;在mozilla扩展js模块中
- 编辑文件重新启动服务器在流星在windows
- Ajax /php无法编辑文件
- 如何编辑文件在执行与node . js
- 使用"file_put_content "创建和编辑文件javascript
- XULRunner忽略已编辑文件的更新