调用函数来终止php脚本

I was wondering if it is possible to call a function to kill the PHP script running, like click on button CANCEL and the function execute.

I tried RESET button but it just removes inputted text/data, even if I stop the page from loading the Apache still executing the script the only way is to stop the Apache itself XAMPP so any help will be appreciated.

if(!$handle = fopen($filename, "rb")) {
    die("Unable to open $filename for read! Make sure you edited filesplit.php correctly!<br>");
}

$base_filename = basename($filename);

$piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);
if(!$fw = fopen($piece_name,"w")) {
    die("Unable to open $piece_name for write. Make sure target folder is writeable.<br>");
}
echo "Splitting $base_filename into $piecesize Mb files <br>"."(last piece may be smaller in size)<br>";
echo "Writing $piece_name<br>";
while (!feof($handle) and $splitnum < 999) {
    if($current < $piece) {
        if($content = fread($handle, $buffer)) {
            if(fwrite($fw, $content)) {
                $current += $buffer;
            } else {
                die("filesplit.php is unable to write to target folder. Target folder may not have write permission! Try chmod +w target_folder<br>");
            }
        }
    } else {
        fclose($fw);
        $current = 0;
        $splitnum++;
        $piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);
        echo "Writing $piece_name...<br>";
        $fw = fopen($piece_name,"w");
    }
}
fclose($fw);
fclose($handle);
echo "Done! <br>";
exit;

function br() {
    return (!empty($_SERVER['SERVER_SOFTWARE']))?'<br>':"
";
}

I think you should submit the code first. Anyway i would like to tell you that die(); is a build in function which kill the all PHP script after calling it. you may try this. OR please submit you code where you want to RESET.