Javascript 在Cloud9IDE上用PHP创建新文件
我正在Chromebook上使用,并试图用PHP编写一个新文件 基本上,当我单击一个按钮时,我使用JQuery的Javascript 在Cloud9IDE上用PHP创建新文件,javascript,php,jquery,ajax,cloud9-ide,Javascript,Php,Jquery,Ajax,Cloud9 Ide,我正在Chromebook上使用,并试图用PHP编写一个新文件 基本上,当我单击一个按钮时,我使用JQuery的$.ajax读取我的php文件,并从php脚本生成hello.txt文件。我有一个警报设置,所以它正在调用函数并读取php文件,但我的新文件没有生成 我的问题是为什么这不起作用,我该如何解决这个问题 index.js $("[data-action=writefile]").click(function(){ $.ajax({ url: 'save.php', su
$.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 ./