How do I download a JPG file from the server?
You can set the response headers from the PHP code to trigger a browser download of the file, e.g, something like:


function digitaliq_bcgrd_variable_file_download($filename) {
  $tmp = variable_get('file_public_path', conf_path().'/files').'/tmp';
  $filepath = $tmp . '/'. $filename;
  if ($data = file_get_contents($filepath)) {
    $file = new stdClass();
    $file-&gt;contents = $data;
    $file-&gt;filename = $filename;
    return EXAMPLE_serve_download($file);
  }
  drupal_not_found();
}


/**
 * Serve a file for download
 * @param $file
 * An object keyed with filename and contents
 */
function EXAMPLE_serve_download($file, $type = 'application/octet-stream') {

  if (empty($file-&gt;contents)) {
    drupal_not_found();
  }

  $headers = array(
    'Content-Type'              =&gt; $type,
    'Content-Disposition'       =&gt; 'attachment; filename="' . $file-&gt;filename . '"',
    'Content-Transfer-Encoding' =&gt; 'binary',
    'Pragma'                    =&gt; 'no-cache',
    'Cache-Control'             =&gt; 'must-revalidate, post-check=0, pre-check=0',
    'Expires'                   =&gt; '0',
    'Accept-Ranges'             =&gt; 'bytes'
  );
  if (ob_get_level()) {
    ob_end_clean();
  }
  foreach ($headers as $name =&gt; $value) {
    drupal_add_http_header($name, $value);
  }

  drupal_send_headers();
  print $file-&gt;contents;
  drupal_exit();

}