Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
php force-download problem
Old 11-05-2004, 03: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
View Public Profile
 
 
Register now for full access!
Old 11-05-2004, 08:31 PM
vivekar's Avatar
Webmaster Talker

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

correct
PHP Code:
header("Content-type: application/octet-stream"); 
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
View Public Profile Visit vivekar's homepage!
 
Old 11-05-2004, 10: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
View Public Profile
 
Old 11-09-2004, 07: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
View Public Profile
 
Old 11-10-2011, 05:35 AM Re: php force-download problem
Junior Talker

Posts: 1
Trades: 0
PLEASE TELL ME HOW YOU DID THAT ? BECAUSE I NEED IT VERY URGENTLY ...

header('Content-type : application/x-octet-stream');
header('Content-Disposition : attachment ;filename="$filename"');

I am using this, but the file is not saving into its format, but to html/text and if i save it to .txt, there is no content !!!

PLEASE REPLY ME
highlander141 is offline
View Public Profile
 
Old 11-10-2011, 01:07 PM Re: php force-download problem
lizciz's Avatar
Webmaster Talker

Posts: 742
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Kind of an old thread to dig up. But for one thing, the OP didn't have quotes (") around the file name. So try changing your second line to either

PHP Code:
header('Content-Disposition : attachment ;filename=' $filename);
// or
header("Content-Disposition : attachment ;filename=$filename"); 
Also, you didn't use the "Content-Transfer-Encoding" and "Content-length" headers.
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366

Last edited by lizciz; 11-10-2011 at 01:10 PM..
lizciz is offline
View Public Profile Visit lizciz's homepage!
 
Old 11-13-2011, 07:53 PM Re: php force-download problem
Giselle's Avatar
"Happy Trails"

Posts: 9,952
Name: Giselle
Location: Washington State
Trades: 0
Thank you Mattias for answering Highlander's question!

@Highlander, in the future please don't bring up old threads and post in them, start your own thread for help.

Thank You,
Giselle
Giselle is offline
View Public Profile
 
Closed Thread     « 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.18339 seconds with 12 queries