We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11093
    • 50 Posts
    Hi, I’m trying to force download for a pdf file, this code works on an antoher website, but with modx file is corrupted on download,
    Is there anything to do like clear cache before sending my file ?
    		header( "Content-type: application/octet-stream" );
    		header( "Content-Disposition: attachment; filename=$file_name" );
    		header( "Content-Type: application/force-download" );
    		header( "Pragma: no-cache" );
    		header( "Cache-Control: must-revalidate, post-check=0, pre-check=0, public" );
    		header( "Expires: 0" );
    		readfile( "{$_POST['filesrc']}" );	

    Please help me ^^ thx
      • 11093
      • 50 Posts
      nobody have an idee ?
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I have had similar problems with a forced download, and found no solution within MODx. I had to "include" an external php file that forced the download then redirected back to the MODx page.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 32982
          • 674 Posts
          for download y create a snippet in the page like it and you dont need to say goodby modx for a mopment and can execute commands like insertion in database when download.
          if ($_REQUEST[’action_send’]=="download"){
          $securepath="THIS IS VERY IMPORTANT FOR PREVENT DOWNLOAD FOR EXAMPLE IN THE MANAGER FOLDER
          $file=$_REQUEST[’url’];//the second part of the url
          PUT HERE THE PATH TO THE ASSETS FOLDER OR UPPER"
          $filename = $securepath.$file;

          // required for IE, otherwise Content-disposition is ignored
          if(ini_get(’zlib.output_compression’))
          ini_set(’zlib.output_compression’, ’Off’);

          // addition by Jorg Weske
          $file_extension = strtolower(substr(strrchr($filename,"."),1));

          if( $filename == "" )
          {
          exit;
          } elseif ( ! file_exists( $filename ) )
          {
          exit;
          };
          switch( $file_extension )
          { //add your types of archives for download...
          case "zip": $ctype="application/zip"; break;
          default: $ctype="application/force-download";
          }
          header("Pragma: public"); // required
          header("Expires: 0");
          header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
          header("Cache-Control: private",false); // required for certain browsers
          header("Content-Type: $ctype");
          // change, added quotes to allow spaces in filenames, by Rajkumar Singh
          header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
          header("Content-Transfer-Encoding: binary");
          header("Content-Length: ".filesize($filename));
          readfile("$filename");
          exit();
          }
            Jabiertxof (formerly XYZVISUAL)
            My bussines: http://marker.es
            https://www.youtube.com/user/jabiertxof/videos
            • 11093
            • 50 Posts
            thx for help, work fine ^^.