<?php
// submit query to search engine
$url_contents = "http://www.google.com/search?q=".urlencode($_POST['query']);
$query_file_content = file_get_contents($url_contents, "r") or die("cannot open url");
// save results to a local file
// depending on how your server is configured you may need to give queryfiles folder 777 permission
// could aslo use another file mode to create file i.e. w+
$file = fopen('queryfiles/'.$_POST['filename'], 'w+');
fwrite ($file, $query_file_content);
fclose($file);
echo "Your Search Has Been Saved To: <a href=queryfiles/".$_POST['filename'].">".$_POST['filename']."</a>";
?>