I am having big troubles gettinga file to force download. I have php script that allows a user to upload a file, the php uploads it using the php ftp commands. the user can also delete the file. This all works fine, and the file uploads alright, if i go through a ftp client and download the uploaded file, the file is fine.
But i want it all php web based. the user can download uplaoded files, but i dont want the download links shown, so im trying to use the header("Content-type: application/force-download"); method, that pops up the save dialog box.
Now when i click on the file, the save dialog pops up and i can save the file to the local disk, but the file is damaged, it is the right size, example: a 15kb jpeg downloads as a 15kb on the localdisk but is damaged and wont open.
I'm kinda lost why the file is doing this, here is the related code:
PHP Code:
$file = $dir.$sub."/".$_REQUEST["file"];
$filename = basename($file);
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-length: ".filesize($file));
header("Content-Disposition: attachment; filename=$filename");
readfile($file);
if i echo out $file it is:
/usr/home/virtual/ptiphoenix.com/webroot/htdocs/downloads/clients/canadaka/documents/small_logo.png
$filename is: small_logo.png
|