PHP Content-disposition: inline?

Posted on 2007-10-10
Last Modified: 2008-01-09
I need to display files through a PHP script. I made me a script named files.php. I call the files as files.php?id=123213 for example.

I get the file to display, or download - regarding if it's an image or not. For images, the image is displayed, but the name of the image is "files.php", if you do a save as you get "files.php.jpg", and i want it to be "something_else.jpg".

I set header("Content-Disposition: attachment; filename=''"), and it works great, for files i want to download.
For images i just want them to display with proper name. Tried header("Content-Disposition: inline; filename='something_else.jpg'") - doesn't work :(

Help? :)

Thanks in advance.
Question by:edmund01
    LVL 14

    Assisted Solution

    make the header as

    Content-Disposition: attachment; filename='something_else.jpg'

    you can always add one more tag to display the image with

    echo "<img src='something_else.jpg'>";

    to display the image
    LVL 9

    Accepted Solution

    Basically to do this you'll need to use mod_rewrite in a .htaccess file or in your http.conf.

    You currently access your page like

    what you should do is something like this for images:

    then in your .htaccess you'll need something like this:

    RewriteEngine On
    RewriteRule ^([0-9]+)\.(jpg|jpeg|png|gif)$ files.php?id=$1

    You can't do it with content disposition I'm afraid.

    Say you don't know it's an image beforehand you could do a header redirect first someone goes to files.php?id=123213 the top of your files.php could do this:


      if (isImageFile($_GET["id"])) { //you need to write isImageFile function yourself
        $filext = getFileExtension($_GET["id"]); // again write this function to get the image extension
        header("location: /{$_GET["id"]}.$filext");

    This combined with the mod_rewrite stuff should give you what you were looking for.

    Author Comment

    Thanks for the answers. None of it really worked. keteracel solution is a bit more what i was looking for, but the name same as ID is not what i want, because behind that ID theres a name saved, thats what i would need. And unless i make DB keys with that name, this won't work.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to count occurrences of each item in an array.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now