从AJAX请求调用的fopen

                <div class="grid--cell fl1 lh-lg">
                    <div class="grid--cell fl1 lh-lg">
                        It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and   cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,   <a href="/help/reopen-questions">visit the help center</a>.

                    </div>
                </div>
            </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2011-06-23 23:25:06Z" class="relativetime">8 years ago</span>.</div>
        </div>
    </aside>

I'm building a WebApp that needs to send a text and a filename through AJAX to the PHP script(on the same place as the Javascript source of course) and the PHP script should save this file on the server, but how to make this?

</div>

That sounds very simple actually. You just send your AJAX request:

$.post("file.php", {filename:"text1.txt", text:"..."});

And in PHP only need:

file_put_contents($dir.basename($_POST["filename"]), $_POST["text"]);

Obviously you need a bit more authorization, a pre-defined save $dir and using basename() is only the minimum security precaution.

Use jQuery and you'll do it like

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

<script type="text/javascript">
$.post('yourscript.php', {filename: 'output.txt', content: 'hello world'});
</script>

Instead of constants you can use textfields for your values. e.g.


$.post('yourscript.php', {filename: $('#filename').val(), content: $('#content').val()});

filename and content within the $-function are the ids of your textfields.