Image MIME/file type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vertuas

    Image MIME/file type

    Hi All,

    Is there a way to get PHP to change the mime type for a file sent to a
    browser.

    I need my website viewers to be able to click a link to directly download
    and save an image, rather than the browser displaying it.

    Is there some other way to make this happen?

    Thanks

    David


  • John Dunlop

    #2
    Re: Image MIME/file type

    Vertuas:
    Is there a way to get PHP to change the mime type for a file sent to a
    browser.
    header('Content-Type: example/*')
    I need my website viewers to be able to click a link to directly download
    and save an image, rather than the browser displaying it.
    Why?
    Is there some other way to make this happen?
    Look up Content-Disposition, but don't hold your breath.

    --
    Jock

    Comment

    • Vertuas

      #3
      Re: Image MIME/file type

      Hi John

      The images are purchased by the user, having them go through an instructions
      page for there browser telling them to right click and save as an all that
      i't would be nicer if they could click a download link, give it a name and
      job done.

      Trouble is linking to the image results in the browser displaying the image,
      rather than downloading it.

      Thanks for the reply.

      David

      "John Dunlop" <usenet+2004@jo hn.dunlop.namew rote in message
      news:1162908302 .192005.238550@ h54g2000cwb.goo glegroups.com.. .
      Vertuas:
      >
      >Is there a way to get PHP to change the mime type for a file sent to a
      >browser.
      >
      header('Content-Type: example/*')
      >
      >I need my website viewers to be able to click a link to directly download
      >and save an image, rather than the browser displaying it.
      >
      Why?
      >
      >Is there some other way to make this happen?
      >
      Look up Content-Disposition, but don't hold your breath.
      >
      --
      Jock
      >

      Comment

      • PleegWat

        #4
        Re: Image MIME/file type

        In article <u%%3h.14794$16 3.13570@newsfe6-gui.ntli.net>, Vertuas says...
        Hi All,
        >
        Is there a way to get PHP to change the mime type for a file sent to a
        browser.
        >
        I need my website viewers to be able to click a link to directly download
        and save an image, rather than the browser displaying it.
        >
        Is there some other way to make this happen?
        You need to send content-type and content-disposition headers, example:

        header('Content-type: image/png');
        header('Content-disposition: attachment; filename="'$fil ename'"');


        --
        PleegWat
        Remove caps to reply

        Comment

        • Vertuas

          #5
          Re: Image MIME/file type

          Thanks again guys

          I found this code on php website

          $f = fopen("file.txt ", "rb");
          $content_len = (int) filesize($f, "file.txt") ;
          $content_file = fread($f, $content_len);
          fclose($f);

          $output_file = 'MXimage.jpg';

          @ob_end_clean() ;
          @ini_set('zlib. output_compress ion', 'Off');
          header('Pragma: public');

          header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
          header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
          header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
          header('Content-Transfer-Encoding: none');
          header('Content-Type: application/octetstream; name="' . $output_file .
          '"'); //This should work for IE & Opera
          header('Content-Type: application/octet-stream; name="' . $output_file .
          '"'); //This should work for the rest
          header('Content-Disposition: inline; filename="' . $output_file . '"');
          header("Content-length: $content_len");

          echo $content_file;
          exit()

          the filename MXimage.jpg is my own test image file.

          when i point IE at it, i get a message about a 3 byte HTML file. Why does
          that image file not come through? It seams that the script doesn't even pass
          the image data on.

          is this something to do with the way PHP handeles the headers. Its running
          on a Linux host.

          Thanks again

          "Vertuas" <vertuas@hotmai l.comwrote in message
          news:u%%3h.1479 4$163.13570@new sfe6-gui.ntli.net...
          Hi All,
          >
          Is there a way to get PHP to change the mime type for a file sent to a
          browser.
          >
          I need my website viewers to be able to click a link to directly download
          and save an image, rather than the browser displaying it.
          >
          Is there some other way to make this happen?
          >
          Thanks
          >
          David
          >

          Comment

          Working...