Returning directory listing with PHP

220 views Asked by At

I am using the following to return the listing of all text files on my server.

echo json_encode(glob("*.{txt}", GLOB_BRACE));

The issue I am having is when I execute this php file from my app, with only one text file in the directory, it returns JSON of the file name as expected, but when I rename that text file, or add additional ones it continues to only return the name of the file that was there on the original run.

I am very new to PHP and am wondering if I am returning cached data instead of getting a refresh each time, or if maybe that is what is happening on my app's side.

Here is the app code:

NSURLSessionDataTask *getTheFileList = [session dataTaskWithURL:[NSURL URLWithString:@"http://www.myserver.com/utility/listJSON2.php"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {


    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    NSEnumerator *enumerator = [json objectEnumerator];
    id value;

    while ((value = [enumerator nextObject]))
    {
        /* code that acts on the dictionary’s values */
        NSLog(@"text file name: %@", value);
    }

}];

Thanks!

1

There are 1 answers

0
Scooter On BEST ANSWER

The answer is that I was indeed receiving cached data and that was causing my problem. The two solutions that I found are to use the ephemeralSessionConfiguration or to use the defaultSessionConfiguration but then to set URLCache = NULL.

Both ways ensure that you are pulling from the server.