在 Cloud9IDE 上的 PHP 中创建新文件
Make new file in PHP on Cloud9IDE
我在我的 Chromebook 上使用 Cloud9IDE 并试图在 PHP 中写入一个新文件。
基本上,当我点击一个按钮时,我使用 JQuery 的 $.ajax
来读取我的 php 文件并从 php 生成 hello.txt 文件脚本。我有一个警报设置,因此它正在调用函数并读取 php 文件,但我的新文件没有生成。
我的问题是为什么这不起作用,我该如何解决这个问题
index.js
$("[data-action=writefile]").click(function(){
$.ajax({
url: 'save.php',
success: function(msg) {
alert('file saved: \n' + msg);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Some error occured");
}
});
});
save.php
<?php
$filename = 'hello.txt';
@ $fp = fopen("exports/".$filename, 'wb');
if (!$fp) {
echo '<p><strong>Cannot generate message file</strong></p></body></html>';
exit;
} else {
$outputstring = 'Hello, i have been generated by the button';
fwrite($fp, $outputstring);
Echo "Message inserted";
}
?>
index.html
<button class="btn--default" data-action="writefile">Write to File</button>
尝试打开您的 cloud9 终端并更改权限:
$ cd /exports
使用 chmod 更改用户权限。
$ chmod 777 -R ./
我在我的 Chromebook 上使用 Cloud9IDE 并试图在 PHP 中写入一个新文件。
基本上,当我点击一个按钮时,我使用 JQuery 的 $.ajax
来读取我的 php 文件并从 php 生成 hello.txt 文件脚本。我有一个警报设置,因此它正在调用函数并读取 php 文件,但我的新文件没有生成。
我的问题是为什么这不起作用,我该如何解决这个问题
index.js
$("[data-action=writefile]").click(function(){
$.ajax({
url: 'save.php',
success: function(msg) {
alert('file saved: \n' + msg);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Some error occured");
}
});
});
save.php
<?php
$filename = 'hello.txt';
@ $fp = fopen("exports/".$filename, 'wb');
if (!$fp) {
echo '<p><strong>Cannot generate message file</strong></p></body></html>';
exit;
} else {
$outputstring = 'Hello, i have been generated by the button';
fwrite($fp, $outputstring);
Echo "Message inserted";
}
?>
index.html
<button class="btn--default" data-action="writefile">Write to File</button>
尝试打开您的 cloud9 终端并更改权限:
$ cd /exports
使用 chmod 更改用户权限。
$ chmod 777 -R ./