Reply
php force-download problem
Old 11-05-2004, 02:30 PM php force-download problem
Junior Talker

Posts: 3
Trades: 0
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
canadaka is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-05-2004, 07:31 PM
vivekar's Avatar
Webmaster Talker

Posts: 574
Trades: 0
wrong
header("Content-type: application/force-download");

correct
PHP Code:
header("Content-type: application/octet-stream"); 
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Old 11-05-2004, 09:29 PM
Junior Talker

Posts: 3
Trades: 0
i changed it too:
header("Content-type: application/octet-stream");

but the file save dialog box tried to save the file as an html document.
canadaka is offline
Reply With Quote
View Public Profile
 
Old 11-09-2004, 06:18 PM
Junior Talker

Posts: 3
Trades: 0
i found the issue, at least the issue that has been stopping it form working this last couple steps.

To test the paths, i was echoing some variables. they were being output before the header. but gave no error. But looking at the file in a hex editor, like you said, i found those echo lines in the file. So I removed the echo's and it seems to be working now! Tested a .png .xls .zip they all work.
canadaka is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php force-download problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.09668 seconds with 13 queries