[PHP] Re: Simple Example of Passing on a file through a PHP script
I want to show info when my docs are viewed though my stats program. I have decieded the best way would be to put the info into a DB through php file then output the PDF, Excel, Zip or Powerpoint file. Only trouble is I have no Idea how to do this Stuffing the actual data into your database doesn't really give you much added value to tracking who is viewing it... Write something like this: -- display.php -- ?php $query = update stats set count = count + 1 where filename = '$filename'; mysql_query($query) or error_log(mysql_error()); # If it's the first time this file has ever been displayed... if (mysql_affected_rows() 1){ $query = insert into stats(filename, count) values('$filename', 1); mysql_query($query) or error_log(mysql_error()); } readfile($filename); ? - You can then put your PDF files *outside* your web-tree so nobody can read them, except like: http://yourserver.com/display.php?filename=foo.pdf -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Simple Example of Passing on a file through a PHP script
Thx. I can output the file using readfile(). But the problem is that it appears to output the data in it's raw form. How can I get it to open in the right application? I wasn't going to put the file in the DB. I am just working on a stats program for a couple of sites. One had about 50 downloads and I want info about who is viewing them also. JJ Harrison [EMAIL PROTECTED] www.tececo.com Richard Lynch [EMAIL PROTECTED] wrote in message news:20020703213010.BFZW903.sccrmhc03.attbi.com@[192.168.1.103]... I want to show info when my docs are viewed though my stats program. I have decieded the best way would be to put the info into a DB through php file then output the PDF, Excel, Zip or Powerpoint file. Only trouble is I have no Idea how to do this Stuffing the actual data into your database doesn't really give you much added value to tracking who is viewing it... Write something like this: -- display.php -- ?php $query = update stats set count = count + 1 where filename = '$filename'; mysql_query($query) or error_log(mysql_error()); # If it's the first time this file has ever been displayed... if (mysql_affected_rows() 1){ $query = insert into stats(filename, count) values('$filename', 1); mysql_query($query) or error_log(mysql_error()); } readfile($filename); ? - You can then put your PDF files *outside* your web-tree so nobody can read them, except like: http://yourserver.com/display.php?filename=foo.pdf -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Simple Example of Passing on a file through a PHP script
On Thursday 04 July 2002 10:46, JJ Harrison wrote: I can output the file using readfile(). But the problem is that it appears to output the data in it's raw form. How can I get it to open in the right application? You _do_ want it to output the data in it's raw form. However it is your responsibility to output the correct headers beforehand so the browser knows what to do with the file. Search archives for download would/should bring up loads of articles on what form the headers should take. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* the butane lighter causes the pincushioning */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Simple Example of Passing on a file through a PHP script
It sort of works now. Here is my script so far: ? $file = strtolower($_GET['filename']); $file_split = explode(., $file); // The number of dots is counted in case a file has two or more dots if($file_split[1] == 'pdf'){ header(Content-type: application/pdf); } elseif($file_split[1] == 'xls') { header (Content-type: application/msexcel); } elseif($file_split[1] == 'zip') { header (Content-type: application/zip); } header (Content-Disposition: attachment; filename=$file ); readfile($file); ? The problem is that with excel files it asks me if I want to download twice. Also it opens in excel not IE. Sometimes PDFs open in IE sometimes the don't. What is wrong? Also would I be better of collecting my stats then using a header to re-direct to the right file(Rather than outputting it through a script)? -- JJ Harrison [EMAIL PROTECTED] www.tececo.com Jason Wong [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Thursday 04 July 2002 10:46, JJ Harrison wrote: I can output the file using readfile(). But the problem is that it appears to output the data in it's raw form. How can I get it to open in the right application? You _do_ want it to output the data in it's raw form. However it is your responsibility to output the correct headers beforehand so the browser knows what to do with the file. Search archives for download would/should bring up loads of articles on what form the headers should take. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* the butane lighter causes the pincushioning */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Simple Example of Passing on a file through a PHP script
I have had inconsistency issues when outputing diffrent content-types to IE. It seems to cache the type for a articular file somewhere and deleting temporary files in the usaer agent is no good. I have to shut-down all instances of IE then re-launch it for it to behave like it is supposed to _consistently_ If I were you, I would just let IE make up it's mind about the file based on it's file extension (it seems to do this automatically based on it's OS settins which are tied into the browser's mime-types). Of course, people may not have excel installed so it won't know what to do with Content-type: application/msexcel If you're trying to exact control over the situation, you're begging for pain. On Thu, 4 Jul 2002 15:23:21 +1000, JJ Harrison [EMAIL PROTECTED] said: It sort of works now. Here is my script so far: ? $file = strtolower($_GET['filename']); $file_split = explode(., $file); // The number of dots is counted in case a file has two or more dots if($file_split[1] == 'pdf'){ header(Content-type: application/pdf); } elseif($file_split[1] == 'xls') { header (Content-type: application/msexcel); } elseif($file_split[1] == 'zip') { header (Content-type: application/zip); } header (Content-Disposition: attachment; filename=$file ); readfile($file); ? The problem is that with excel files it asks me if I want to download twice. Also it opens in excel not IE. Sometimes PDFs open in IE sometimes the don't. What is wrong? Also would I be better of collecting my stats then using a header to re-direct to the right file(Rather than outputting it through a script)? -- JJ Harrison [EMAIL PROTECTED] www.tececo.com Jason Wong [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Thursday 04 July 2002 10:46, JJ Harrison wrote: I can output the file using readfile(). But the problem is that it appears to output the data in it's raw form. How can I get it to open in the right application? You _do_ want it to output the data in it's raw form. However it is your responsibility to output the correct headers beforehand so the browser knows what to do with the file. Search archives for download would/should bring up loads of articles on what form the headers should take. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* the butane lighter causes the pincushioning */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php [TK] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php