Обсуждение: manage stored files via web
Hello. Sorry for off-topic, but... I have the following problem. I'm developing system with ability to store files inside it. Files are being stored in postgres as large objects. The problem is, that actual file names are stored along with LO oids. When user wants to download some file, it clicks on link: "...?oid=<oid>&action=get" and browser suggests strange name for file being downloaded (currently it suggests domain name or link text as file name). What I want is that file name suggested by browser would be the one, stored in DB. I currently enclose it in Content-type: HTTP header, but that seems to be not working. Thanks in advance. -- Victor Yegorov
Вложения
It would be better if you haven't gone to far already to save the files into an level above the web directory and simply save the link to the file into a varchar in the DB. Then just call the link into an <a href="">. G -----Original Message----- From: Victor Yegorov [mailto:viy@pirmabanka.lv] Sent: 20 March 2003 10:47 To: Postgres PHP Subject: [PHP] manage stored files via web Hello. Sorry for off-topic, but... I have the following problem. I'm developing system with ability to store files inside it. Files are being stored in postgres as large objects. The problem is, that actual file names are stored along with LO oids. When user wants to download some file, it clicks on link: "...?oid=<oid>&action=get" and browser suggests strange name for file being downloaded (currently it suggests domain name or link text as file name). What I want is that file name suggested by browser would be the one, stored in DB. I currently enclose it in Content-type: HTTP header, but that seems to be not working. Thanks in advance. -- Victor Yegorov
* Grant Henderson <granth@fusion-advertising.co.uk> [20.03.2003 12:58]: > It would be better if you haven't gone to far already to save the files > into an level above the web directory and simply save the link to the > file into a varchar in the DB. > Then just call the link into an <a href="">. > I'm saving them not directly on my disk, I store them inside my POstgreSQL database as Large Object. -- Victor Yegorov
Вложения
* Matt Palmer <matthew.palmer@abcmail.co.uk> [20.03.2003 13:18]: > are the jpegs only memory-resident or are they actually on-disk at any point?? Nor memory resident, neither on disk. They are inside DB, to extract them i need to use pg_lo_open, pg_lo_read funcs. Then I have a string, containing file data. And I don't want to store them on disk, I'd like to output them directly, specifing the name of the file somehow. But how? -- Victor Yegorov
Вложения
On Thu, 20 Mar 2003, Victor Yegorov wrote: > What I want is that file name suggested by browser would be the one, stored > in DB. I currently enclose it in Content-type: HTTP header, but that seems > to be not working. content-type, as name sais, is to suggest a 'type' of the file, should browser try to show the file (in case its plaintext/html) or should it call a plugin (ms word = "application/msword"). What you want is you want to suggest that 1. browser saves the file 2. browser use different name than the url one. for this purpose you got in header option to do "Content-Disposition". Here I must warn you that IE expects Content-Disposition handled differently than other browsers. Here is what I used to do: ---- $myfakefilename = readFileName_FromDB(); if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) // For IE header("Content-Disposition: filename=$myfakefilename" . "%20"); else // For Other browsers header("Content-Disposition: attachment; filename=$myfakefilename"); ---- enjoy, /apz, Sometimes you get an almost irresistible urge to go on living.
* apz <apz@nofate.com> [20.03.2003 15:37]: > On Thu, 20 Mar 2003, Victor Yegorov wrote: > > What I want is that file name suggested by browser would be the one, stored > > in DB. I currently enclose it in Content-type: HTTP header, but that seems > > to be not working. > > content-type, as name sais, is to suggest a 'type' of the file, should > browser try to show the file (in case its plaintext/html) or should it > call a plugin (ms word = "application/msword"). > > What you want is you want to suggest that > 1. browser saves the file > 2. browser use different name than the url one. > > for this purpose you got in header option to do "Content-Disposition". > Here I must warn you that IE expects Content-Disposition handled > differently than other browsers. Here is what I used to do: > > ---- > $myfakefilename = readFileName_FromDB(); > if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) // For IE > header("Content-Disposition: filename=$myfakefilename" . "%20"); > else // For Other browsers > header("Content-Disposition: attachment; filename=$myfakefilename"); > ---- Great, exactly what I needed. One question - what for is "%20"? Explorer adds "[1]" suffix, when this space present. I've removed it. Thank you. -- Victor Yegorov
Вложения
On Thu, 20 Mar 2003, Victor Yegorov wrote: > * apz <apz@nofate.com> [20.03.2003 15:37]: > > On Thu, 20 Mar 2003, Victor Yegorov wrote: > > > What I want is that file name suggested by browser would be the one, stored > > > in DB. I currently enclose it in Content-type: HTTP header, but that seems > > > to be not working. > > for this purpose you got in header option to do "Content-Disposition". > > Here I must warn you that IE expects Content-Disposition handled > > differently than other browsers. Here is what I used to do: > > ---- > > $myfakefilename = readFileName_FromDB(); > > if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) // For IE > > header("Content-Disposition: filename=$myfakefilename" . "%20"); > > else // For Other browsers > > header("Content-Disposition: attachment; filename=$myfakefilename"); > > ---- > Great, exactly what I needed. > > One question - what for is "%20"? Explorer adds "[1]" suffix, when this > space present. I've removed it. actually I dont really know, i found it somewhere on the net. As I was working with embedding documents from db (item with item image in db as well), the content-disposition was actually causing problems for some browsers as they assumed that although the file is to be embedded <img src=getImage.php?itemcode=9346a> browsers got confused by the content-disposition and were assuming that download is necessary. As I really didnt need to use content-disposition I removed teh code. I know now that there is also content-disposition inline (vs attachment). you can read more on content-disposition at: http://www.php.net/manual/en/function.header.php /apz, pain, n.: One thing, at least it proves that you're alive!