0

My code works fine with my local server, but when put on my production server (shared hosting) the text files won't write. If I manually navigate to the location of the text files and refresh, the changes are made. I've tried changing the file permissions (777 and 755) on the text files and the php files and still nothing. I'm at a complete loss.

The code:

PHP

$json = file_get_contents($search); 

    $searchf = fopen('../data/id.json', 'w');
    fwrite($searchf,$json);
    fclose($searchf);

Also works in localhost written like this:

    $searchf = "../data/id.json";
    file_put_contents($searchf,$json);

Ajax/jQuery

$.ajax({
    url: 'includes/ig-id.php',
    type: "post",
    data: {
        'user': user
    },
    success: function () {
        //Get IG id
        $.getJSON("data/id.json", function (response) {
            var data = response;
            data = data.data[0].id;

            //Send response to function
            instaFeed(data);
        });
    }
});

function instaFeed(data) { 
var feed = data;
$feed.html("");
$.ajax({
    url: 'includes/ig-user.php',
    type: "post",
    data: {
        'feed': feed
    },
    success: function () {
        //Get IG feed
        $feed.html("");

        $.getJSON("data/feed.json", function (response) {
            $feed.html("");

            var data = response;
            var length = 10; 

            $spin.css("display", "none"); //CSS spinner

            for (var i = 0; i < length; i++) {
                var $img = $("<img>", {
                    src: data.data[i].images.thumbnail.url
                });
                //Send response to page
                $("#feed").append($img);
            }
        }).fail(function () {
            $spin.css("display", "none");
            $feed.html("This artist's Instagram is private.");
        });
    }
});

}

Again all this works fine in MAMP and has worked on my school's production server so I think its a problem with my personal server's configuration?

Reck
  • 68
  • 3
  • PHP under linux uses the user permissions of the host server when performing file operations. For example; Check what permissions the Apache user for the daemon has for that target directory. I also don't understand what "If I manually navigate to the location of the text files and refresh, the changes are made. " means? – Reactgular Jun 29 '14 at 16:23
  • I meant that if I type the url if the text file in the browser then refresh, the file will have the correct information. Without doing that, it doesn't update. – Reck Jun 29 '14 at 16:30

1 Answers1

0

It was a file permissions issue. My hosting provider does not allow file permissions to be set to 777.

Reck
  • 68
  • 3