Trying to create a new php file from a template file using the PHP script below. There are no errors but the script is not working.
<?php
//loop through stock.json
$stock = json_decode("../stock.json");
$stockValue = $stock["stock"];
try {
for($i = 0; $i < sizeof($stockValue); $i++) {
$stock_id = $stockValue[i][0];
//read template
$template = file_get_contents("../../product_pages/product_page-0000.php");
//create new file
if (!file_exists("../../product_pages/product-".$stock_id.".php")) {
$handle = fopen("../../product_pages/product_page-".$stock_id.".php", "c+");
fwrite($handle,$template);
fclose($handle);
}
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
The script is supposed to open "product_page-0000" and then save a copy of it with the new filename "product_page-$stock_id". $stock_id is obtained from the json file "stock.json".
The script is currently not outputting anything and there are no error codes.