Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 962 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PHP] Force file download

#1
Some files, such as mp3, are generally played throught the client browser. If you prefer forcing download of such files, this is not a problem: The following code will do that job properly.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

Reply

#2
Really all you need it application/octet-stream as your mime type. That tells the browser that it is binary and cannot be displayed.

To do this in PHP you also need to provide 2 additional headers to follow HTTP specification.

The content disposition header set to attachment will tell the browser what to save it as... Instead of a random filename with query string like "whatever.php?d=12422&file=blah"

The content length header is required by HTTP 1.0, but not by HTTP 1.1, it is expected... If the file size cannot be determined it should be given the chunked attribute, this allows the HTTP 1.1 compliant client to determine if it has received the correct amount off data or not, and will return to the server whether or not it has.
PHP Code:
<?php
header 
("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit; 
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through