Jump to content

File download


ToonMariner

Recommended Posts

Hi people.

I am having a little problem. I have a file download script that is working fine (for most users) but some report that the dialouge box that allows you to choose open or save (and subsequently pick where to save) is not displaying.

The download begins automatically and users cannot find the file on their machines. I have just managed to replicate this in IE7 and it is a bit annoying!!! ;) Avant (using IE7's engine) works ok. IE6 with pop-up blocker installed has the same problem when you allow pop-ups from this site otherwise it blocks the pop-up.

here is the download file..

[code]<?php

$error = NULL;
$filename = isset($_GET['file']) ? $_GET['file'] : NULL;

if (
ini_get('zlib.output_compression')
)
{
ini_set('zlib.output_compression', 'Off');
}

$file_extension = strtolower(substr(strrchr($filename,"."),1));

if (
is_null($filename)
)
{
$erro = "Error: No file path passed to script.";
exit;
}
else
{
$first_char = substr($filename,0,1);
if (
$first_char == "/"
)
{
$filename = substr(strtolower($filename), 1);
}
if (
!file_exists($_SERVER['DOCUMENT_ROOT'] . "/" . $filename)
)
{
$error = "Error: No such file found.";
exit;
}
}
switch ($file_extension)
{
case "pdf":
$ctype = "application/pdf";
break;
case "exe":
$ctype = "application/octet-stream";
break;
case "zip":
$ctype = "application/zip";
break;
case "doc":
$ctype = "application/msword";
break;
case "xls":
$ctype = "application/vnd.ms-excel";
break;
case "ppt":
$ctype = "application/vnd.ms-powerpoint";
break;
case "gif":
$ctype = "image/gif";
break;
case "png":
$ctype = "image/png";
break;
case "jpeg":
case "jpg":
$ctype = "image/jpg";
break;
default:
exit();;
}


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: ' . $ctype);
header('Content-Disposition: attachment; filename="' . basename($filename) . '";' );
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($filename));
readfile($filename);
exit();

?>[/code]

PS As a side I would dearly love to get the downloads working as they do from download.com instead of this pop-up being the driving force.  How can you achieve a download that is NOT affected by the pop-up blockers (or should I say what other method are available that could combat this issue.)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.