views:

185

answers:

1

Hi all

I'm trying to create a file download page. This page when requested should prompt the user to download a file. Here is the source code for the page:

<?php
header('Content-disposition: attachment; filename=zip.zip')

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

readfile('zip.zip');

?>

This works ok.

The problems starts when I want to move the file zip.zip from the folder where this script is in. I tried using relative and absolute URLs but I always get strange results, the browser still prompts for file download but somehow it's just an odd file name converted from the URI I supplied somthing like ".._.._files_zip.zip instead of ../../files/zip.zip.

Any suggestions why this happens? Thanks

+1  A: 

Use basename to get just the file name:

$file = '../../files/zip.zip';
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Type: application/zip');
readfile($file);
Gumbo
thanks for this :)this worked it outhighly appreciate the help
Yaniv