Jump to content
  • 0

скачивание на лету


solos
 Share

Question

файл index.php

____________________________________________________

<?php

Error_Reporting(E_ALL & ~E_NOTICE);

function Downloadfile ($filename)

{

$handle = fopen($filename, 'rb');

if ($handle === false)

{

return false;

}

while (!feof($handle))

{

print (fread($handle, 1024*8));

ob_flush();

flush();

}

fclose($handle);

return true;

}

Downloadfile("z:/home/test1.ru/www/file/1.rar");

?>

____________________________________________________

Выкидает страницу с содержимым архива.

Мне нужно чтобы выкидало окошко сохранить файл. Что нужно дописать?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
Можно добавить в скрипт header:

header('Content-type: application/rar');

А если файл не rar?

<?php

error_reporting(E_ALL & ~E_NOTICE);

function Downloadfile ($filename)
{
if(!file_exists($filename)) return false;

if(!headers_sent())
{
header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-type: application/octet-stream');
}

echo file_get_contents($filename);

return true;
}

Downloadfile('z:/home/test1.ru/www/file/1.rar');

?>

Link to comment
Share on other sites

  • 0

header("Pragma: public");

header("Expires: 0");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Cache-Control: private",false);

header("Content-Type: application/octet-stream");

header("Content-Disposition: attachment; filename={$row['name']}");

header("Content-Transfer-Encoding: binary");

header("Content-Length: ".@filesize(FILE_DIR.$row['onserver']));

@set_time_limit(0);

@Downloadfile(FILE_DIR.$row['onserver']) or die("File not found.");

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy