0

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>':"\n";
}
7
  • 2
    You need to learn about how php works: youtube.com/watch?v=PemsuAfc7Jw Commented Jan 16, 2017 at 19:12
  • until that happen you can help thanks in advance Commented Jan 16, 2017 at 20:22
  • 1
    @kyo_adam I'm helping you the way you need to be helped of. Learning how php operates (its so simple that its explained that 3 minutes video) you largely improve your vision about it, and thus, your programming will be more easy Commented Jan 16, 2017 at 20:35
  • i know and thank you i love php language is there any way to contact you on private please Commented Jan 16, 2017 at 20:41
  • sorry, the SO don't offer ways to send/receive private messages. I think theres no problem to post your problems here Commented Jan 16, 2017 at 22:06

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

die() and exit() yeah but how to do that, i have already a form with a submit button but is it possible to call those functions or other with a click ??
i have told you to submit the code. without knowing the code how could anyone say what you want to do where you have not specified anything clearly.
the die() goes on your php script (those lines of code between the <?php and ?>. The click to submit a form will call the action of the form (your form action is index.php). So, your index.php file must have a php code that handles submited data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.