How can I display a thank you page after uploading user files?

I am using this small pusher php file to upload an exe file for saving by the user when he fills out the form.

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);

with this method there is no link to the online location of the $ file so that someone will follow, but for some reason I cannot display the thank you page after or even immediately before the code is executed.

I tried the headline ("Location: $ thankyouurl"); immediately after the above code, but nothing is displayed, and I tried to repeat the html source of the thank you page before running the above code, but this causes the exe file to load on the web page, actually breaking the browser,

Any suggestions???

+5
source
4

, . JavaScript, window.location script.

, , .

, JavaScript.

:

index.php

<a href="thankyou.php">Click here to download.</a>

thankyou.php

<html>
<head>
    <script type="text/javascript">
        function startDownload() {
            window.location = "/download.php";
        }
    </script>
</head>
<body onload="startDownload();">
    <h1>Thank you!</h1>
    <p>Your download will start in a moment. If it doesn't, use this <a href="download.php">direct link.</a></p>
</body>

download.php

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);

Update

index.php script, GET. thankyou.php thankyou.php?download=12, - . script, :

index.php

<a href="thankyou.php?download=12">Click here to download.</a>

thankyou.php

<html>
<head>
    <script type="text/javascript">
        function startDownload() {
            window.location = "/download.php?file=<?=$_GET['download']?>";
        }
    </script>
</head>
<body onload="startDownload();">
    <h1>Thank you!</h1>
    <p>Your download will start in a moment. If it doesn't, use this <a href="download.php?file=<?=$_GET['download']?>">direct link.</a></p>
</body>

script .

+14

,...

header('Location: thanks_page.php');

... ,. readfile()? , !

0

You can open the "download page" using "windows.open (" url to download the file ")"

Example:

<script type="text/javascript">
    function openDownload()
    {
        window.open( "http://domain.com/download.php?file=file.pdf" );
        window.location = "http://domain.com/thanks.php";
    }
</script>

Opening a window directly loading the file will automatically be closed when you select to save or cancel, and then the "parent" window will be redirected to the page with thanks.

0
source

Using your original method, add header('location: thank-you-page.php');to the end along with the output, as shown below:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);

header('location: thank-you-page.php');
exit;
0
source

All Articles