internet explorer - Does anyone know of a good script to force file downloads and yet protect download links on a PHP server? -


I tried to use a free script found on the internet but it is giving me problems with Windows users (even if They are using IE 8, so I do not have the option to ask them to upgrade their browser.) Here are the requirements:

  • I have Microsoft Word and PDF files There is a group that needs to be protected The authorized users can download them. I have already created the login system and the existing script, which I have worked well for non-IE browsers. However, I keep recurring problems with Windows users who complain that their files corrupt and so far everyone is using Mac or Linux or any other browser, just fine.
  • The script should allow me to store files in the directory, but the function forces the file to download the file.
  • Should work well with most major browsers, especially IE

if you have any suggestions or know about any great scripts ( Even if they have been paid, I am sick of this problem and will probably pay for a payment script) It will be highly appreciated in advance.

Here is the code of the function I am currently using:

  function output_file ($ file, $ name, $ mime_type = '') {if (! Is_readable ($ File) dead ('file not found or missing!'); $ Size = filesize ($ file); $ Name = rawurldecode ($ name); / * MIME type (if not specified) * / $ Gyat_man_taip = Array ( "PDF" = & gt; "application / pdf", "txt" = & gt; "text / plain", "html" = & gt; = "Gtc: mediawiki-xid =" gtc: "/ GSP" = "gtc: mediawiki-xid =" gtc: suffix = "" gtc: mediawiki-xid = "image / jpg", "JPG" = & gt; " Image / jpg "," php "= & gt;" text / plain "," RTF "= & gt;" application / RTF "," CSV "=>" Text / CSV "); If ($ mime_type == '') {$ file_extension = strtolower (substr (strrchr ($ file, "."), 1)); If (array_key_exists ($ file_extension, $ known_mime_types)) {$ mime_type = $ known_mime_types [$ file_extension]; } And {$ mime_type = "app / force-download"; }; }; @ob_end_clean (); // close the output buffer to reduce the required CPU usage to IE, otherwise content-controversy can be ignored if (ini_get ( 'zlib.output_compression')) ini_set ( 'zlib.output_compression', 'off' ); Header ('Content-Type:'. $ Mime_type); Header ('content-dispute: attachment; filename =' '. $ Name.' '' '); Header ("content-transfer-encoding: binary"); Header ('accept-range: bytes'); / * Create three rows originally downloaded non-cacheable * / header ("Cache-Control: Private"); Header ('Predama: Private'); Header ("End: Mon, 26 July 1997 05:00:00 GMT"); // multipart- Download and support resume if (isset ($ _ server ['HTTP_RANGE'])) {list ($ a, $ range) = explosion ("=", $ _ server ['HTTP_RANGE] '], 2); List ($ range) = explosion (",", $ range, 2); List ($ range, $ range_end) = explosion ("-", $ range); $ Range = intval ($ range); If (! $ Range_end) {$ range_end = $ size-1; } And ($ range_end = intval ($ range_end);} $ New_length = $ range_end- $ range + 1; header ( "HTTP / 1.1 206 Partial Content"); header ( "Content-Length: $ new_length"); Top The article ("content-rank: $ size- $ range_end / $ size");} and {$ new_length = $ size; header ("content-length:". $ Size);} / * output file itself * / $ Chunksize = 1 * (1024 * 1024); // You may want to change this $ bytes_send = 0; if ($ file = fopen ($ file, 'r')) (if (isset ($ _ server) [ 'HTTP_RANGE'])) ($ file, $ range); while (! Fif ($ file) & amp; amp; (! Knekshn_borted ()) & amp; amp; ($ Bait_send & lt; $ new_length)) {$ Buffer = Fred ($ file, $ choisex); print ($ buffer); // echo ($ buffer); // is also possible flush; $ byte_send + = strollon ($ buffer);} Fclose ($ File);} and die ('error - file can not open'); die ();}  

Actually, it is very easy to do this. It includes only a few header calls and a readfile.

PHP manual gives you maximum code to do this, just how to do it To use the filename from another location CODE NO.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -