示例#1
0
function loadFormData()
{
    if (isset($_GET["name"])) {
        //check if recipe name was passed through URL
        $filename = "recipes/" . $_GET["name"] . ".recipe";
        //mount the filename with relative PATH
        if (file_exists($filename)) {
            //if it is the first time loading and file exists
            return requireCarrega();
            //then load the file values
        } else {
            //not sure if anything should be done here
        }
    }
}
    $s = file($path, FILE_IGNORE_NEW_LINES);
    //le arquivo da receita salva
    $count = 0;
    //variavel de iteracao
    foreach ($variables as &$v) {
        //apesar de variables ter key => value, usar soh value
        $v = unserialize($s[$count]);
        //copia um array no outro
        $count++;
    }
    $result = fclose($file);
    if (!$result) {
        echo "Erro ao carregar receita!";
        return;
    }
    return $variables;
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["name"])) {
    //check if recipe name was passed through URL
    $filename = "../recipes/" . $_POST["name"] . ".recipe";
    //mount the filename with relative PATH
    if (file_exists($filename)) {
        //if it is the first time loading and file exists
        echo json_encode(requireCarrega($filename));
        //then load the file values and return to server
    } else {
        //not sure if anything should be done here
        echo json_encode("Recipe " . $_POST["name"] . " not available");
        //return to server that recipe is not available
    }
}