Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Php fopen is not working through jquery ajax

$
0
0
$("input.class_input_button_send").on("click",function(event) {
               event.preventDefault();
               //var username = $("input.class_input_hidden").val();
               var typed_text = $("input#id_input_text_type").val();
               console.log(typed_text);
               rt = $.ajax({
                    type: "POST",
                    url: "send.php",
                    data: { name: "", typed_text: typed_text },
                    success: function(data) {
                        console.log(data);
                        console.log(data.length);
                    }
                }).done(function() {
                    alert( "success" );
                    })
                  .fail(function() {
                    alert( "error" );
                });
               //console.log(rt);
           });
send.php =><?php
<?php
    if( session_id() == '' ) {
        session_start();
    }
    if($_SERVER['SERVER_PROTOCOL'] == "HTTP/1.1") {
        $domain_host_root = "http://" . $_SERVER['SERVER_NAME'] . "/";
    }
    require_once 'core/model/mysql/mysqldb.php';
    require_once 'core/utility/debug-app.php';
    require_once 'core/utility/utility.php';
    require_once 'core/view/view.php';
    
    //$_POST['typed_text'] = "abc";
    $typed_text = $_POST['typed_text'];
    $objDateTime = new DateTime('NOW');

    $target_file = $objDateTime->format("Y-m-d");
    $handle = fopen("archive/" . $target_file . ".txt", "w+");
    fwrite($handle, $target_file_data);
    echo json_encode($target_file);
?>
fopen function is working inside that send.php script if i run this as a standalone script, but fopen function returns null through the jquery $.ajax() function.

Viewing all articles
Browse latest Browse all 13200

Trending Articles