Hi! I've got a little script for downloading files and displaying them in a new tab or browser-window. I simply want the filename to be displayed as the title of the page that's opened. If I add title-tags anywhere it starts to complain which I guess is normal.

It seems so simple, and I figure the header-function have to be able to send the title since it's a header, right? However I've Googled a lot but can't find it, not even a word on the PHP-documents on the header-function about page-title.

www.php.net/header

What am I missing? Every site I know have the title displayed in the browser window when you watch files. My download-script looks something like this:

header("Content-length: " . $row['size']);
header("Content-type: " . $row['type']);
header("Content-Disposition: inline; filename=\"" . $row['name'] . "\"");

And not much more that's interesting. It looks up the database from a id that's sent in the link you click on like "download.php?id=1". It's just like all the download-script tutorials out there, but they also seem to neglect changing the title of the page. Anyway, thanks!

    Watching a file and downloading a file are two different processes. You can't set browser bar's title with [man]header[/man]

      Ok, is there any other way change the page's title without upsetting PHP? I'm sorry if that part is a little unclear. The way I understood it when you download a file with the header functions the browser just wants those headers for filename, type and size. If I try to squeeze in a title-tag, or the full html-, head- and title-tags it won't work. Even a blank space have been upsetting it.

        Yeah, ok they're two different things. However if I add:

        echo '<head><title>row['name']</title></head>';

        Here:

        
        $result = mysql_query("select name, size, type, content from file where userid=" . $_SESSION['user_id']);
        $row = mysql_fetch_array($result); 
        
        echo '<head><title>row['name']</title></head>';
        
        header("Content-length: " . $row['size']);
        header("Content-type: " . $row['type']);
        header("Content-Disposition: inline; filename=\"" . $row['name'] . "\"");
        echo $row['content'];

        And try to open a PDF-document that's stored in my database Adobe Reader tells me the file is corrupted. I figured this was so because it only wants the response-headers and nothing else. I had a problem earlier where I had a blank space in download.php which corrupted all my files.

        If I try to open a TXT-file it succeeds but I get the words "echo '<head><title>Page Title</title></head>';" at the top in the text of the file (not browser title), so yeah: Everything that's echo'd in the download.php-file is printed to the file I'm displaying it seems.

        That's why I thought I wanted to send the title in headers in some way. Isn't this possible, or am I missing something else?

          Kudose is right; you're not talking about a page title, you're talking about the window title of a Windows application.

          Sure, using a <title> HTML element should modify the window title of your internet browser when viewing HTML pages, but you can't use it (or any other method) to modify window titles of other applications on your computer.

          EDIT: And just to be more general, replace "Windows" with the name of the O/S you're running.

            Ok, I think I understand. So whenever there's a link on a site to a PDF or JPEG and the title of the browser changes that file is actually there in the web-server folder. Good to know, thanks for the replies 🙂

              Write a Reply...