【问题标题】:Make new file in PHP on Cloud9IDE在 Cloud9IDE 上用 PHP 创建新文件
【发布时间】:2015-09-14 01:33:01
【问题描述】:

我在我的 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>

【问题讨论】:

    标签: javascript php jquery ajax cloud9-ide


    【解决方案1】:

    尝试打开您的 cloud9 终端并更改权限:

    $ cd /exports
    

    使用 chmod 更改用户权限。

    $ chmod 777 -R ./ 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-01
      • 1970-01-01
      • 2021-04-24
      • 2011-06-23
      • 1970-01-01
      • 2021-12-13
      • 2015-07-25
      • 1970-01-01
      相关资源
      最近更新 更多