Support » Plugin: BulletProof Security » 403 – Trying to download an image

  • Resolved 123ben



    I have a download link on my website for different images. This is the href:


    The download.php looks like this:

    $file_url = $_GET['file'];
    function retrieve_remote_file_size($url){
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_HEADER, TRUE);
     curl_setopt($ch, CURLOPT_NOBODY, TRUE);
     $data = curl_exec($ch);
     $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
     return $size;
    $filesize = retrieve_remote_file_size($file_url);
    if($filesize != -1){
      if($filesize < 52428800){
        if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');
        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: application/force-download');
        header("Content-Transfer-Encoding: Binary");
        header("Content-disposition: attachment; filename=\"".basename($file_url)."\"");
        header("Content-Length: ".$filesize);
        echo 'The requested file is too large.';
      header('HTTP/1.0 404 Not Found');

    When I click the link my browser tells me that the file size is 0 bytes (which of course isn’t true).

    In the BPS error log this is all I got (remote_addr, host name and request uri altered):

    >>>>>>>>>>> 403 GET or Other Request Error Logged – July 8, 2013 – 23:13 <<<<<<<<<<<
    Host Name:
    REQUEST_URI: /path/to/image/image.jpg

    I don’t know what to do. Could someone please give me a hint which custom code have to be entered?

    All the best

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author AITpro


    Your User Agent is blank so this may or may not be the problem, but either way you do not want to have a blank User Agent. And you should also add follow location.

    Not real sure about the Header and Body options since I have never used them before but something seems off/contradictory. In any case a cURL file download only requires a couple of simple options – see this simple example –

    CURLOPT_HEADER	=> true, // TRUE return headers - False don't return headers
    CURLOPT_NOBODY	=> true, // TRUE to exclude the body from the output. Request method is then set to HEAD.
    curl_setopt($ch, CURLOPT_USERAGENT, 'Add a User Agent here');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    Have you put BPS in Default Mode and deactivated the wp-admin BulletProof Mode for testing? Does the cURL download script work?

    Thanks for your respond. I tried the script with no luck too. It doesn’t work with BPS in Default Mode either. I don’t know at which point the problem occurs. I also asked the plugin developer for guidance…

    Plugin Author AITpro


    Yep, if the script does not work when BPS is in Default Mode then it is a problem with the download script itself.

    Here is an example of a simple working cURL download script.

    $url  = '';
    $path = 'C:\xampp\htdocs\demo/';
    $useragent = 'MyFileGrabber';
       $ch = curl_init($url);
       curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
       $data = curl_exec($ch);
          if ( curl_errno($ch) ) {
             echo 'Curl error: ' . curl_error($ch);
          } else {
             $info = curl_getinfo($ch);
          echo 'Success! Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'].'<br>';
          echo 'Downloaded File Path: ' . $path;
       file_put_contents($path, $data);
    Plugin Author AITpro


    Resolving since this is not an issue/problem with BPS.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘403 – Trying to download an image’ is closed to new replies.