Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Cloud9IDE上用PHP创建新文件_Javascript_Php_Jquery_Ajax_Cloud9 Ide - Fatal编程技术网

Javascript 在Cloud9IDE上用PHP创建新文件

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

我正在Chromebook上使用,并试图用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 ./