move a json file in php

To move a JSON file in PHP, you can use the rename() function to move the file from its current location to a new location. Here's how you can do it:

main.php
// Specify the current file path
$currentFilePath = '/path/to/current/file.json';

// Specify the new file path
$newFilePath = '/path/to/new/file.json';

// Move the file to the new location
if (rename($currentFilePath, $newFilePath)) {
    echo "JSON file moved successfully.";
} else {
    echo "Error moving JSON file.";
}
326 chars
13 lines

In the code above, we first specify the current file path and the new file path. We then use the rename() function to move the file from the current path to the new path. The function returns a boolean value indicating whether the operation was successful or not, so we can use an if-else statement to print a message accordingly.

gistlibby LogSnag