OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 11 Aug 2005 07:13:48 -0000 Issue 3618

php-general-digest-helplists.php.net
Date: Thu Aug 11 2005 - 02:13:48 CDT


php-general Digest 11 Aug 2005 07:13:48 -0000 Issue 3618

Topics (messages 220354 through 220405):

Re: dynamic object instances
        220354 by: Matthew Weier O'Phinney
        220374 by: Thomas Angst
        220391 by: Jochem Maas
        220394 by: Eli
        220395 by: Jochem Maas
        220398 by: Eli

html_entity_decode () for …, ’, etc.
        220355 by: Marco
        220362 by: Leon Vismer
        220366 by: Richard Lynch
        220367 by: Jim Moseby
        220381 by: Jasper Bryant-Greene

Gathering CPU info from Linux and FreeBSD and placing it into a MySQL db
        220356 by: Patrick - Jupiter Hosting
        220371 by: Nathan Tobik
        220377 by: Patrick - Jupiter Hosting
        220382 by: Greg Donald
        220387 by: Patrick - Jupiter Hosting
        220388 by: Robert Cummings

Re: force download
        220357 by: Sebastian
        220358 by: Sebastian
        220359 by: Chris
        220364 by: Richard Lynch
        220365 by: Richard Lynch
        220378 by: Sebastian
        220386 by: Richard Lynch
        220405 by: Norbert Wenzel

what should I look for with this error
        220360 by: Bruce Gilbert
        220361 by: Jay Blanchard
        220363 by: Bruce Gilbert
        220368 by: John Nichel
        220373 by: Jay Blanchard
        220375 by: Jay Blanchard
        220392 by: Jochem Maas

Re: display error line in object method
        220369 by: Richard Lynch
        220397 by: comex

Re: Restarting windows from php
        220370 by: Richard Lynch
        220372 by: Richard Lynch
        220384 by: Richard Davey
        220385 by: Tyler Kiley
        220390 by: Jochem Maas

Re: graph - dowloads/hr
        220376 by: Richard Lynch

Re: php output to string
        220379 by: Richard Lynch

Re: Regular expressions book
        220380 by: Anas Mughal

Re: rename an uploaded file.
        220383 by: Richard Lynch

Redisplaying information from a HTML form
        220389 by: Ravi Gogna
        220396 by: Jochem Maas

Re: N/A
        220393 by: Jochem Maas

How efficient is OOP in PHP5?
        220399 by: TalkativeDoggy

Sockets and SOAP
        220400 by: Eli

date field
        220401 by: John Taylor-Johnston
        220402 by: Jasper Bryant-Greene
        220403 by: Ben Ramsey

PHP GD and Unicode
        220404 by: Louie Miranda

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


* Thomas Angst <ta_phpgranitsoft.ch>:
> I would like to create an object inside a function with its classname
> and a parameter list submitted by the function call.
>
> function create($class, $parameter) {
> $obj = new $class($parameter);
> return $obj;
> }
>
> This is working very well. But I have not every time the same count of
> parameters for a class constructor.
> If this is a normal method call of an object I can realise it like this:
>
> $ret = call_user_func_array(array(&$obj, 'method'), $parameter_array);
> The $parameter_array contains as many entries as the function needs.
> Works well too.
>
> But how can I write a function to instance objects with various count of
> parameters in the constructor?
> I know, can do this with an eval. But I would like to find a solution
> where I don't need an eval.

Use the func_* functions, along with array_shift(). In addition, you'll
need to use either a standard-named static instantiator, or the class
name as the constructor method:

function create($class) {
    $args = func_get_args();
    array_shift($args); // remove $class from the args list

    // Do this if using a standard-named static instantiator method
    // across classes; in this case 'init':
    return call_user_func_array(array($class, 'init'), $args);

    // Or use a function named after the class name as the instantiator
    // method (ala PHP4):
    return call_user_func_array(array($class, $class), $args);
}

--
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/

attached mail follows:


Matthew Weier O'Phinney schrieb:

>Use the func_* functions, along with array_shift(). In addition, you'll
>need to use either a standard-named static instantiator, or the class
>name as the constructor method:
>
>function create($class) {
> $args = func_get_args();
> array_shift($args); // remove $class from the args list
>
> // Do this if using a standard-named static instantiator method
> // across classes; in this case 'init':
> return call_user_func_array(array($class, 'init'), $args);
>
> // Or use a function named after the class name as the instantiator
> // method (ala PHP4):
> return call_user_func_array(array($class, $class), $args);
>}
>
>
Thanks for you answer, but sorry, I do not understand your hint. I tried
this code:
class test {
    var $txt;
    function test($txt) { $this->txt = $txt; }
    function out() { echo $this->txt; }
}
$obj = call_user_func_array(array('test', 'test'), array('foobar'));
$obj->out();
But I'm getting an error while accessing the $this pointer in the
constructor.

Thomas

attached mail follows:


Thomas Angst wrote:
> Hello List,
>
> I would like to create an object inside a function with its classname
> and a parameter list submitted by the function call.
>
> function create($class, $parameter) {
> $obj = new $class($parameter);
> return $obj;
> }
>
> This is working very well. But I have not every time the same count of
> parameters for a class constructor.
> If this is a normal method call of an object I can realise it like this:
>
> $ret = call_user_func_array(array(&$obj, 'method'), $parameter_array);
> The $parameter_array contains as many entries as the function needs.
> Works well too.
>
> But how can I write a function to instance objects with various count of
> parameters in the constructor?
> I know, can do this with an eval. But I would like to find a solution
> where I don't need an eval.

to keep it easy have your ctors be able to except an assoc array as the first
argument as an alternative to its normal arg list - or just use an assoc array
period - that combined with a call to expand() in the ctor.

then... something like:

function create($class, $params)
{
        if (!class_exists($class)) {
                return null;
        }

        return new $class( $params );
}

<TAKE_NOTE>
btw if your on php4 your probably what to be using lots of f'ing '&' signs.
</TAKE_NOTE>

alternatively it's either:

1. use eval() - yuck
2. make all your objects have empty ctors and force them to have an _init()
method that actually does the work e.g.

function create($class)
{
        if (!class_exists($class)) {
                return null;
        }

        $params = func_get_args();
        $params = array_slice($params, 1);

        $o = new $class();
        call_user_func_array(array($o, '_init'), $params);
        return $o;
}

3. re-evaluate what you are trying to achieve with the create function.
maybe you need a factory base class instead? (for instance)
>
> thanks for all answers,
> Thomas
>

attached mail follows:


Thomas Angst wrote:
> Thanks for you answer, but sorry, I do not understand your hint. I tried
> this code:
> class test {
> var $txt;
> function test($txt) { $this->txt = $txt; }
> function out() { echo $this->txt; }
> }
> $obj = call_user_func_array(array('test', 'test'), array('foobar'));
> $obj->out();
> But I'm getting an error while accessing the $this pointer in the
> constructor.

This will not work, since it is like calling a static class method, and
$this is not allowed to be used in static methods.

I solved this with eval() function.
<?
$obj_eval="return new $class(";
for ($i=0; $i<count($args); $i++)
    $obj_eval.="\$args[$i],";
$obj_eval=substr($obj_eval,0,-1).");";
$obj=eval($obj_eval);
?>

attached mail follows:


Eli wrote:
> Thomas Angst wrote:
> > Thanks for you answer, but sorry, I do not understand your hint. I tried
> > this code:
> > class test {
> > var $txt;
> > function test($txt) { $this->txt = $txt; }
> > function out() { echo $this->txt; }
> > }
> > $obj = call_user_func_array(array('test', 'test'), array('foobar'));
> > $obj->out();
> > But I'm getting an error while accessing the $this pointer in the
> > constructor.
>
> This will not work, since it is like calling a static class method, and
> $this is not allowed to be used in static methods.
>
> I solved this with eval() function.
> <?
> $obj_eval="return new $class(";
> for ($i=0; $i<count($args); $i++)
> $obj_eval.="\$args[$i],";
> $obj_eval=substr($obj_eval,0,-1).");";
> $obj=eval($obj_eval);
> ?>

I believe that this is the kind of clever, evil stuff the OP was trying to avoid...
(evil - eval :-) - besides eval is very slow - not something you (well me then) want to
use in a function dedicated to object creation which is comparatively slow anyway
(try comparing the speed of cloning and creating objects in php5 for instance

regardless - nice one for posting this Eli - I recommend anyone who doesn't understand
what he wrote to go and figure it out, good learning material :-)

>

attached mail follows:


Jochem Maas wrote:
> Eli wrote:
>> <?
>> $obj_eval="return new $class(";
>> for ($i=0; $i<count($args); $i++)
>> $obj_eval.="\$args[$i],";
>> $obj_eval=substr($obj_eval,0,-1).");";
>> $obj=eval($obj_eval);
>> ?>
>
>
> I believe that this is the kind of clever, evil stuff the OP was trying
> to avoid...
> (evil - eval :-) - besides eval is very slow - not something you (well
> me then) want to
> use in a function dedicated to object creation which is comparatively
> slow anyway
> (try comparing the speed of cloning and creating objects in php5 for
> instance
>
> regardless - nice one for posting this Eli - I recommend anyone who
> doesn't understand
> what he wrote to go and figure it out, good learning material :-)
>
>>
You're right that using eval() slows.. But using the _init() function as
you suggested is actually tricking in a way you move the constructor
params to another function, but the initialization params should be sent
to the constructor!

I guess that it would be better if PHP will add a possibility to
construct a dynamic class with variant number of params... ;-)

attached mail follows:


I tried using html_entity_decode () but why won't these characters decode:

&rsquo;
&ndash;
&hellip;
&ldquo;
&rdquo;

attached mail follows:


Hi Marco

To awnser you question I do not know why it is excluded from the default
decode array. Maybe it could be that these are multibyte characters (any
takers)?

You can get a list of the entities that are changed

$trans = get_html_translation_table(HTML_ENTITIES);
echo"<pre>";print_r($trans);echo"</pre>";

to add some extras as you have below, use something similar to

function htmldecode($string)
{
        $trans = get_html_translation_table(HTML_ENTITIES);
        $trans[chr(0xe2).chr(0x80).chr(0xa6)] = '&hellip;';
        $trans = array_flip($trans);
        return strtr($string, $trans);
}

$string = "&hellip;&amp;";
echo htmldecode($string) ."\n";

Note: obviously hex e2 80 a6 make up the hellip chars.

Hope this helps

Cheers

--
Leon

On Wednesday 10 August 2005 20:55, Marco wrote:
> I tried using html_entity_decode () but why won't these characters decode:
>
> &rsquo;
> &ndash;
> &hellip;
> &ldquo;
> &rdquo;

attached mail follows:


On Wed, August 10, 2005 11:55 am, Marco wrote:
> I tried using html_entity_decode () but why won't these characters decode:
>
> &rsquo;
> &ndash;
> &hellip;
> &ldquo;
> &rdquo;

WILD GUESS:
Those are not standards-based, and are some made-up Microsoft crap?

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


> > &hellip;

Is this the IP range assigned to hell? I always suspected they were on the
net.

JM

attached mail follows:


Richard Lynch wrote:
> On Wed, August 10, 2005 11:55 am, Marco wrote:
>
>>I tried using html_entity_decode () but why won't these characters decode:
>>
>>&rsquo;
>>&ndash;
>>&hellip;
>>&ldquo;
>>&rdquo;
>
> WILD GUESS:
> Those are not standards-based, and are some made-up Microsoft crap?

Nah, they are standard HTML entities. Depending on your PHP version, you
may like to try playing with the third parameter, perhaps setting it to
"UTF-8". See the following URL for more information:

http://www.php.net/html_entity_decode

AFAIK multibyte encodings such as UTF-8 aren't supported by some PHP
versions though. It may be a PHP 5 feature?

Jasper

attached mail follows:


Hey all,

First time poster to this mailing list, but I've been lurking for a week
now, and it seems like there are a lot of helpful people on this list.
I hope to help others out with problems I can answer for them in the
future.

Now, I have an important task at hand. My company has assigned me to
write a script that will log into both our BSD and Linux boxes (we have
about 400 boxes), gather up all the information about each system
(Operating System, External IP Address, LAN Controller, Video Card, USB
devices, Serial Port, Amount of Memory, # of Hard Drives, HD Brand, and
HD Type (ide ata scsi raid)).

We've gone over a few ideas, although we're not set in stone which route
we want to take, or if there is an easier solution to this task at hand.
Heck, even if there is something that has already been coded and can act
as a foundation for this project would be grand.

Okay, so here's what we've come up with so far:

1) Using parts of PHPSysInfo

- Hack apart this script I found called phpsysinfo. I've already hacked
it apart and it only displays what we're looking for. You can see what
I'm talking about if you visit
http://morano.hopto.org/phpsysinfo/index.php

- Use the XML portion of the script to export all gathered data into an
XML file.

- Take the XML file and import it into the MySQL db

2) Finding a script that already does all this already (Ideal Solution)

- I'm open to ideas on this one. After snooping around Linux and BSD,
I've gathered that using a combination of sysctl, uname, and dmesg would
get me the results I need, but this seems like the hard way, unless
someone has already implemented a solution using these tools and PHP.
Finding a script that already does everything I want IS the ideal
solution, the trouble is finding it.

I know it can be done, but I've been bashing my head against the wall
for the past day and a half now. My head hurts and has a couple knots
due to the wall being so thick, so now I turn to you folks in search for
some guidance.

If there is anything else I can answer to help clarify my task at hand,
please let me know. I'm stepping out for lunch, but I'm pretty much
stuck at work until a solution has been found, so I'll be checking the
mailing list frequently (about every 5 mins!).

The URL I provided to contains everything that is needed to be gathered.

Also, if there are other resources such as forums, web site tutorials,
script archives, etc. that I might be able to find answers from, I'd
love to check them out.

Thanks in advance.

Patrick

attached mail follows:


Can I ask why you are trying to write a script that from what I
understand goes to each box to retrieve the data instead of pushing the
data to the central db?

You could write a little script in PHP that gathers the required
information and then does an insert into your database. Then from the
database you can create a webpage that is a view of all of your
machines. On the local machine you can schedule your script to run
every X minutes via crontab.

If I misread your email and headed down the wrong path please let me
know.

Nate Tobik
(412)661-5700 x206
VigilantMinds

<snip...>

attached mail follows:


Hi Nate,

We are a hosting company. We use this Mambo-like CMS called CATS, which
pretty much tells us what company owns what server(s) in our data
centers. CATS will provide us with a list of details on the specs for
each machine they own, which include the specs I listed (memory, # of
cpus, etc.) Someone in our company deleted the table within the MySQL
db that listed our 400+ machines. Since IT is slammed with other tasks,
they have assigned me to this job.

This is a step by step as to what I've decided needs to happen, in order
for this task to operate (somewhat) smoothly.

1) Read IP addresses from a tab-delimited file, which will follow the
format:

abc.com 64.64.64.1
domain.com 255.213.6.4
blah.co.uk 29.42.200.9
etc.net 13.14.15.255

2) Assign the $domain variable to the domain name in each line, then
assign $ipaddress to the actual ip address

3) Take $ipaddress and ssh into each box (we have a private/public ssh
key set up)

4) (This is the undecided step) Run script to gather the necessary
server information and export info into either a)CSV or b)XML

5) Take exported file and upload it/email it to my box/my email address

6) Take exported file and create a script to import the information into
the CATS MySQL db (not handled by me, but I can easily take over
responsibility on creating this script and implement it into my code)

7) Lather, rinse, repeat :)

Hope this helps to clear up some information. I got more answers to any
questions anyone might have. Thanks again :)

Patrick

On Wed, 2005-08-10 at 16:41 -0400, Nathan Tobik wrote:
> Can I ask why you are trying to write a script that from what I
> understand goes to each box to retrieve the data instead of pushing the
> data to the central db?
>
> You could write a little script in PHP that gathers the required
> information and then does an insert into your database. Then from the
> database you can create a webpage that is a view of all of your
> machines. On the local machine you can schedule your script to run
> every X minutes via crontab.
>
> If I misread your email and headed down the wrong path please let me
> know.
>
> Nate Tobik
> (412)661-5700 x206
> VigilantMinds
>
>
>
> <snip...>
>

attached mail follows:


On 8/10/05, Patrick - Jupiter Hosting <patrick1100tech.com> wrote:
> Hi Nate,
>
> We are a hosting company. We use this Mambo-like CMS called CATS, which
> pretty much tells us what company owns what server(s) in our data
> centers. CATS will provide us with a list of details on the specs for
> each machine they own, which include the specs I listed (memory, # of
> cpus, etc.) Someone in our company deleted the table within the MySQL
> db that listed our 400+ machines. Since IT is slammed with other tasks,
> they have assigned me to this job.

Sounds like you want Nagios.

http://www.nagios.org/

--
Greg Donald
Zend Certified Engineer
MySQL Core Certification
http://destiney.com/

attached mail follows:


Hi Greg,

Thanks for the link, although I don't think this is exactly what I am
looking for. I am looking for a rather simple way to automate the ssh
into each box and gathering of the system information, instead of
monitoring the servers. This is going to be a one time operation, as
once we gather all the information, regular backups will (finally) be
made so this won't happen again in the future.

With this now being my 2nd week into the job, I'm learning that the new
people who just joined the company are replacing the rather unorganized
people who have thrown us into this rut.

Thanks again for the link (that's a rather cool piece of software!), but
I think I'm looking for something a tad more simple. Got any more links
to throw at me? :)

Patrick

On Wed, 2005-08-10 at 16:13 -0500, Greg Donald wrote:
> On 8/10/05, Patrick - Jupiter Hosting <patrick1100tech.com> wrote:
> > Hi Nate,
> >
> > We are a hosting company. We use this Mambo-like CMS called CATS, which
> > pretty much tells us what company owns what server(s) in our data
> > centers. CATS will provide us with a list of details on the specs for
> > each machine they own, which include the specs I listed (memory, # of
> > cpus, etc.) Someone in our company deleted the table within the MySQL
> > db that listed our 400+ machines. Since IT is slammed with other tasks,
> > they have assigned me to this job.
>
> Sounds like you want Nagios.
>
> http://www.nagios.org/
>
>
> --
> Greg Donald
> Zend Certified Engineer
> MySQL Core Certification
> http://destiney.com/
>

attached mail follows:


On Wed, 2005-08-10 at 19:07, Patrick - Jupiter Hosting wrote:
> Hi Greg,
>
> Thanks for the link, although I don't think this is exactly what I am
> looking for. I am looking for a rather simple way to automate the ssh
> into each box and gathering of the system information, instead of
> monitoring the servers. This is going to be a one time operation, as
> once we gather all the information, regular backups will (finally) be
> made so this won't happen again in the future.
>
> With this now being my 2nd week into the job, I'm learning that the new
> people who just joined the company are replacing the rather unorganized
> people who have thrown us into this rut.
>
> Thanks again for the link (that's a rather cool piece of software!), but
> I think I'm looking for something a tad more simple. Got any more links
> to throw at me? :)

You might try an "expect" script and call it from PHP.

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


James R. wrote:

> That would be browser dependent, something you have no control over.
> Maybe you can include a little text message saying "right-click save
> as" for the users not intelligent enough to figure it out themselves.
>
>
> ----- Original Message ----- From: "Sebastian"
> <sebastianbroadbandgaming.net>
> To: <php-generallists.php.net>
> Sent: Wednesday, August 10, 2005 12:00 PM
> Subject: [PHP] force download
>
>
>> some of my users are complaining that when they try download media
>> files (mp3, mpeg, etc) their media player opens and doesn't allow
>> them to physically download the media. These are IE users, firefox
>> seems to like my code, but IE refuses to download the file and plays
>> it instead..
>>
>> can anyone view my code and see how i can force media file downloads
>> on IE?
>>
>> --snip--
>>
>> header('Cache-control: max-age=31536000');
>> header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . '
>> GMT');
>> header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file['date']) .
>> ' GMT');
>>
>> if ($extension != 'txt')
>> {
>> header("Content-disposition: inline; filename=\"$file[type]\"");
>> }
>> else
>> {
>> // force txt files to prevent XSS
>> header("Content-disposition: attachment; filename=\"$file[type]\"");
>> }
>>
>> header('Content-Length: ' . $file['size']);
>>
>> switch($extension)
>> {
>> case 'zip':
>> $headertype = 'application/zip';
>> break;
>> case 'exe':
>> $headertype = 'application/octet-stream';
>> break;
>>
>> case 'mp3':
>> $headertype = 'audio/mpeg';
>> break;
>>
>> case 'wav':
>> $headertype = 'audio/wav';
>> break;
>> case 'mpg':
>> $headertype = 'video/mpeg';
>> break;
>>
>> case 'avi':
>> $headertype = 'video/avi';
>> break;
>>
>> default:
>> $headertype = 'unknown/unknown';
>> }
>>
>> header('Content-type: ' . $headertype);
>>
>> --/snip--
>>
>>
>>
>
there has to be a way to tell stupid IE Not to open the damn file. i'll
be damned to find a way.

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.5/67 - Release Date: 8/9/2005

attached mail follows:


James R. wrote:

> That would be browser dependent, something you have no control over.
> Maybe you can include a little text message saying "right-click save
> as" for the users not intelligent enough to figure it out themselves.
>
>
> ----- Original Message ----- From: "Sebastian"
> <sebastianbroadbandgaming.net>
> To: <php-generallists.php.net>
> Sent: Wednesday, August 10, 2005 12:00 PM
> Subject: [PHP] force download
>
>
>> some of my users are complaining that when they try download media
>> files (mp3, mpeg, etc) their media player opens and doesn't allow
>> them to physically download the media. These are IE users, firefox
>> seems to like my code, but IE refuses to download the file and plays
>> it instead..
>>
>> can anyone view my code and see how i can force media file downloads
>> on IE?
>>
>> --snip--
>>
>> header('Cache-control: max-age=31536000');
>> header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . '
>> GMT');
>> header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file['date']) .
>> ' GMT');
>>
>> if ($extension != 'txt')
>> {
>> header("Content-disposition: inline; filename=\"$file[type]\"");
>> }
>> else
>> {
>> // force txt files to prevent XSS
>> header("Content-disposition: attachment; filename=\"$file[type]\"");
>> }
>>
>> header('Content-Length: ' . $file['size']);
>>
>> switch($extension)
>> {
>> case 'zip':
>> $headertype = 'application/zip';
>> break;
>> case 'exe':
>> $headertype = 'application/octet-stream';
>> break;
>>
>> case 'mp3':
>> $headertype = 'audio/mpeg';
>> break;
>>
>> case 'wav':
>> $headertype = 'audio/wav';
>> break;
>> case 'mpg':
>> $headertype = 'video/mpeg';
>> break;
>>
>> case 'avi':
>> $headertype = 'video/avi';
>> break;
>>
>> default:
>> $headertype = 'unknown/unknown';
>> }
>>
>> header('Content-type: ' . $headertype);
>>
>> --/snip--
>>
forgot to mention, they can't right click to "save as" because if you
notice from my code i am pushing the file to them... without an actual
path to the file. so if they did do a "save as" it'll just save the
php/html output, which will be blank in this case.

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.5/67 - Release Date: 8/9/2005

attached mail follows:


A comment is inline.

Sebastian wrote:

> some of my users are complaining that when they try download media
> files (mp3, mpeg, etc) their media player opens and doesn't allow them
> to physically download the media. These are IE users, firefox seems to
> like my code, but IE refuses to download the file and plays it instead..
>
> can anyone view my code and see how i can force media file downloads
> on IE?
>
> --snip--
>
> header('Cache-control: max-age=31536000');
> header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . '
> GMT');
> header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file['date']) . '
> GMT');
>
> if ($extension != 'txt')
> {
> header("Content-disposition: inline; filename=\"$file[type]\"");
> }
> else
> {
> // force txt files to prevent XSS
> header("Content-disposition: attachment; filename=\"$file[type]\"");
> }
>
if you just remove this extension check, and set everything as an
attachment, that is the normal way to do things. The major browsers will
pop up a Save As... dialog

> header('Content-Length: ' . $file['size']);
>
> switch($extension)
> {
> case 'zip':
> $headertype = 'application/zip';
> break;
> case 'exe':
> $headertype = 'application/octet-stream';
> break;
>
> case 'mp3':
> $headertype = 'audio/mpeg';
> break;
>
> case 'wav':
> $headertype = 'audio/wav';
> break;
> case 'mpg':
> $headertype = 'video/mpeg';
> break;
>
> case 'avi':
> $headertype = 'video/avi';
> break;
>
> default:
> $headertype = 'unknown/unknown';
> }
>
> header('Content-type: ' . $headertype);
>
> --/snip--
>
>

attached mail follows:


On Wed, August 10, 2005 12:49 pm, Chris wrote:
>> if ($extension != 'txt')
>> {
>> header("Content-disposition: inline; filename=\"$file[type]\"");
>> }
>> else
>> {
>> // force txt files to prevent XSS
>> header("Content-disposition: attachment; filename=\"$file[type]\"");
>> }

The Content-disposition header is a made-up bull-crap thing that came
about with "html enhanced" (cough, cough) email.

If you want *EVERY* browser to download something, forget this header and
use:

header("Content-type: application/octet-stream");

The Content-disposition will, on *SOME* browsers, on *SOME* OSes appear to
be useful for getting the filename in the dialog prompt for "Save As..."
to be the filename you want.

Unfortunately, it does *NOT* work universally.

If you want a UNIVERSAL solution, make the URL look like it's a "static"
URL and have the filename you want to be used appear at the end of the
URL.

Converting dynamic to static-looking URLs is covered in many places.
Google for PHP $_SERVER PATHINFO

Under no circumstances should you be using headers like "audio/mpeg" if
you want me to download it -- I guarantee my browser will open that up in
an MP3 player. Many other users will also have been led through the
process to make that happen.

But if the browser doesn't download "application/octet-stream" it's a very
very very broken browser.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Wed, August 10, 2005 12:43 pm, Sebastian wrote:
>> That would be browser dependent, something you have no control over.
>> Maybe you can include a little text message saying "right-click save
>> as" for the users not intelligent enough to figure it out themselves.

I defy you to find any web browser that doesn't download a file whose
Content-type: header is application/octet-stream

Right-click is NOT universal.

Macs don't even *have* a right-click!

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


Richard Lynch wrote:

>On Wed, August 10, 2005 12:49 pm, Chris wrote:
>
>
>>>if ($extension != 'txt')
>>>{
>>> header("Content-disposition: inline; filename=\"$file[type]\"");
>>>}
>>>else
>>>{
>>> // force txt files to prevent XSS
>>> header("Content-disposition: attachment; filename=\"$file[type]\"");
>>>}
>>>
>>>
>
>The Content-disposition header is a made-up bull-crap thing that came
>about with "html enhanced" (cough, cough) email.
>
>If you want *EVERY* browser to download something, forget this header and
>use:
>
>header("Content-type: application/octet-stream");
>
>The Content-disposition will, on *SOME* browsers, on *SOME* OSes appear to
>be useful for getting the filename in the dialog prompt for "Save As..."
>to be the filename you want.
>
>Unfortunately, it does *NOT* work universally.
>
>If you want a UNIVERSAL solution, make the URL look like it's a "static"
>URL and have the filename you want to be used appear at the end of the
>URL.
>
>Converting dynamic to static-looking URLs is covered in many places.
>Google for PHP $_SERVER PATHINFO
>
>Under no circumstances should you be using headers like "audio/mpeg" if
>you want me to download it -- I guarantee my browser will open that up in
>an MP3 player. Many other users will also have been led through the
>process to make that happen.
>
>But if the browser doesn't download "application/octet-stream" it's a very
>very very broken browser.
>
>

if i don't use Content-disposition IE downloads the file as "unknown"
(mp3, exe, or otherwise) with no extension and the names the file you
are downloading becomes the name of the script that was called. lol?

can never win with IE ..

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.5/67 - Release Date: 8/9/2005

attached mail follows:


On Wed, August 10, 2005 2:07 pm, Sebastian wrote:
> if i don't use Content-disposition IE downloads the file as "unknown"
> (mp3, exe, or otherwise) with no extension and the names the file you
> are downloading becomes the name of the script that was called. lol?

So here's what you do.

Go ahead and RENAME your PHP script to "next_hit_song.mp3"

Then use .htaccess to tell Apache that it's *REALLY* a PHP script even
though it ends in .mp3

<Files next_hit_song.mp3>
  application/x-httpd-php
</Files>

That is what I mean by making the URL look "static"

IE is so [bleeping] stupid about URLs and content-type and rich media,
that you simply cannot give it any room for a mistake.

Consider the MP3s and m3u s on the pages here:
http://uncommonground.com/
http://uncommonground.com/artist_profile/Ellen+Rosner

Every one of the MP3/m3u files you can find there is really a PHP script.

They just happen to end in .mp3 and .m3u so IE can't [bleep] up.

The dynamic MP3 downloads (and streams) have the MP3 ID3 tags inserted at
download time, so the artists can correct typos or give me info like song
title and whatnot lonnnnnnng after the actual mp3 is created, identified,
and cataloged.

The m3u playlists are coming out the database from queries with all kinds
of "interesting" properties.

New playlist every day on the homepage.

Different playlist every download on the calendar pages:
http://uncommonground.com/events.htm

While you are there, check out that PDF.

Yup.

That ain't really a PDF, it's a PHP script. But even IE can't manage to
screw up when the URL is http://uncommonground.com/events.pdf

I do need to fix the ones where the date (past/future months) is passed as
a GET argument. Some versions of IE on the Mac mess that up. Sigh. In
my spare time.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


> Sebastian wrote:
>
>> some of my users are complaining that when they try download media
>> files (mp3, mpeg, etc) their media player opens and doesn't allow them
>> to physically download the media. These are IE users, firefox seems to
>> like my code, but IE refuses to download the file and plays it instead..
>>
>> can anyone view my code and see how i can force media file downloads
>> on IE?

We're using the PHP based 'Moodle' system and had the similar problems
when downloading stuff in IE. On some IEs it worked, on some IE did
nothing, though it was the same version. The only way to fix this, was
to search for a 'IE' String, in the browser info and to show another
page, with a stupid 'Save as...' link to IE users.

hope that works,
norbert

attached mail follows:


I get this error a lot, and think it may be an easy fix, but don't
really know what to look for.

'Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in
/hsphere/local/home/bruceg/inspired-evolution.com/Contact_Form_Test.php
on line 556'

what does this indicate?

--
::Bruce::

attached mail follows:


[snip]
I get this error a lot, and think it may be an easy fix, but don't
really know what to look for.

'Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in
/hsphere/local/home/bruceg/inspired-evolution.com/Contact_Form_Test.php
on line 556'

what does this indicate?
[/snip]

Two and a half words..... missing semi-colon - usually just above the
line mentioned.

attached mail follows:


I don't see any missing semi-colons off hand. The error is supposedly
on line 556 in the below code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/subpage_template.dwt"
codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Wealth Development Mortgage :: TEAM</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" --> <!-- InstanceEndEditable -->
<link href="WDM.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main" > <!-- InstanceBeginEditable name="header" -->
  <div id="header">
    <div id="logo"> <img src="/test/images/logo.gif" alt="Wealth
Development Mortgage" ></div>
    <div id="slogan"><img src="/test/images/slogan.gif" alt="company
slogan" ></div>
    <div id="top_navigation">
      <ul id="topnav">
        <li><a href="">HOME</a></li>
        <li class="border_left"><a href="">CONTACT US</a></li>
        <li class="border_left"><a href="">PAYMENT CALCULATOR</a></li>
      </ul>
    </div>
  </div>
  <!-- InstanceEndEditable -->
  <!-- end header and begin main content information -->
  <!-- InstanceBeginEditable name="mainnav" -->
  <div id="mainnav">
    <ul id="navlist">
      <li class="border_right"><a href="../index.htm" title="home
link">HOME</a></li>
      <li class="border_right"><a href="#" title="company information"
>COMPANY</a></li>
      <li class="border_right"><a href="#" title="about the team">TEAM</a></li>
      <li class="border_right"><a href="#" title="contact us">CONTACT</a></li>
      <li><a href="#" title="fill out our on-line application">APPLY
ONLINE</a></li>
    </ul>
  </div>
  <!-- InstanceEndEditable -->
  <!-- flash will go here, image used as placeholder for now -->
  <div id="flash">
    <img src="/test/images/flash_image.jpg" alt="for position only">
  </div>
 
 <div id="page_title_bar">
   

    <!-- InstanceBeginEditable name="page_header" --><h1>TEAM</h1><!--
InstanceEndEditable -->
  </div>
  <!-- InstanceBeginEditable name="maincontent" -->
  <table class="Loan_Application" title="Secure Loan Application"
cellspacing="0" summary="Full Loan Application for Wealth Development
Mortgage Company">
      
  <caption>
  Secure Loan Application
  </caption>
  <tr>
    <td class="header">Wealth Development Mortgage Company provides
fast mortgage approvals online.<br>
      Your Application will be placed in top priority and receive
immediate attention.</td>
  </tr>
  <tr>
    <td>
        <?php
$form_block=<<<END_FORM
<form method="POST" action="{$_SERVER['PHP_SELF']}" class="loan_application">
<fieldset>
       <fieldset>
        <legend title="Loan Information">LOAN INFORMATION</legend>
        
        <table>
          <tr>
            <td > <table>
                <tr>
                  <td colspan="2"><label for="loan_purpose" >Loan
Purpose:</label>
                    <br> <select
                        name="purpose" id="purpose">
                      <option value="Purchase"
                          selected>Purchase</option>
                      
                      <option
                          value="refinance_no_cash">Refinance - No Cash</option>
                      <option
                          value="refinance_cash_out">Refinance - Cash
Out</option>
                      
                      <option
value="refinance_debt_consolidation">Refinance - Debt
Consolidation</option>
                      <option
                          value="refinance_change_loan_type">Refinance
- Change Loan Type</option>
                      <option value="construction_loan">Construction
Loan</option>
                      <option value="other_loan_purpose">Other Loan
Purpose</option>
                    </select></td>
                  <td><label for="property_use">Property Use:</label>
                    <br>
                                        <select class="textbox"
                        name="property" id="property">
                <option value="">Select One</option>
                <option
                          value="" selected>----------</option>
                <option
                          value="primary_residence">Primary Residence</option>
                <option
                          value="secondary_residence">Secondary
Residence</option>
                <option
                          value="investment_property">Investment
Property</option>
              </select>
                  </td>
                </tr>
                <tr>
                  <td colspan="2">Loan Type:
                    <br> <select
                          name="loan_type" id="loan_type">
                      <option value="30_year_fixed" selected>30 Year
Fixed</option>
                      <option value="15_year_fixed">15 Year Fixed</option>
                                          <option value="10_arm">10/1 ARM</option>
                                          <option value="7_arm">7/1 ARM</option>
                                          <option value="5_arm">5/1 ARM</option>
                                           <option value="3_arm">3/1 ARM</option>
                                            <option value="1_arm">1 year ARM</option>
                                                <option value="6m_arm">6 month ARM</option>
                                                <option value="option_arm">0ption ARM</option>
                                                <option value="10_interest">10 year Interest Only</option>
                                                <option value="5_interest">5 year Interest Only</option>
                                                <option value="3_interest">3 year Interest Only</option>
                                                <option value="HELOC">HELOC</option>
                    </select></td>
                                        <td><label for="property_type">Property Type:</label><br>
                                        <select class="textbox" name="property_type" id="property_type">
                                        <option value="single_family_detached">Single Family Detached</option>
                                        <option value="townhouse">Townhouse</option>
                                        <option value="condo">Condo</option>
                                        <option value="multi_unit">Multi Unit</option>
                                        </select>
                                        </td>
                  <td><label for="interest_rate">Interest Rate:</label>
                    <br> <select class="textbox"
                        name="interest_rate" id="interest_rate">
                      <option value="" selected>Select One</option>
                      <option value="">----------</option>
                      <option value="1.000">1.000</option>
                      <option
                          value="1.125">1.125</option>
                      <option
                          value="1.250">1.250</option>
                      <option
                          value="1.375">1.375</option>
                      <option
                          value="1.500">1.500</option>
                      <option
                          value="1.625">1.625</option>
                      <option
                          value="1.750">1.750</option>
                      <option
                          value="1.875">1.875</option>
                      <option
                          value="2.000">2.000</option>
                      <option
                          value="2.125">2.125</option>
                      <option
                          value="2.250">2.250</option>
                      <option
                          value="2.375">2.375</option>
                      <option
                          value="2.500">2.500</option>
                      <option
                          value="2.625">2.625</option>
                      <option
                          value="2.750">2.750</option>
                      <option
                          value="2.875">2.875</option>
                      <option
                          value="3.000">3.000</option>
                      <option
                          value="3.125">3.125</option>
                      <option
                          value="3.250">3.250</option>
                      <option
                          value="3.375">3.375</option>
                      <option
                          value="3.500">3.500</option>
                      <option
                          value="3.625">3.625</option>
                      <option
                          value="3.750">3.750</option>
                      <option
                          value="3.875">3.875</option>
                      <option
                          value="4.000">4.000</option>
                      <option
                          value="4.125">4.125</option>
                      <option
                          value="4.250">4.250</option>
                      <option
                          value="4.375">4.375</option>
                      <option
                          value="4.500">4.500</option>
                      <option
                          value="4.625">4.625</option>
                      <option
                          value="4.750">4.750</option>
                      <option
                          value="4.875">4.875</option>
                      <option
                          value="5.000">5.000</option>
                      <option
                          value="5.125">5.125</option>
                      <option
                          value="5.250">5.250</option>
                      <option
                          value="5.375">5.375</option>
                      <option
                          value="5.500">5.500</option>
                      <option
                          value="5.625">5.625</option>
                      <option
                          value="5.750">5.750</option>
                      <option
                          value="5.875">5.875</option>
                      <option
                          value="6.000">6.000</option>
                      <option
                          value="6.125">6.125</option>
                      <option
                          value="6.250">6.250</option>
                      <option
                          value="6.375">6.375</option>
                      <option
                          value="6.500">6.500</option>
                      <option
                          value="6.625">6.625</option>
                      <option
                          value="6.750">6.750</option>
                      <option
                          value="6.875">6.875</option>
                      <option
                          value="7.000">7.000</option>
                      <option
                          value="7.125">7.125</option>
                      <option
                          value="7.250">7.250</option>
                      <option
                          value="7.375">7.375</option>
                      <option
                          value="7.500">7.500</option>
                      <option
                          value="7.625">7.625</option>
                      <option
                          value="7.750">7.750</option>
                      <option
                          value="7.875">7.875</option>
                      <option
                          value="8.000">8.000</option>
                      <option
                          value="8.125">8.125</option>
                      <option
                          value="8.250">8.250</option>
                      <option
                          value="8.375">8.375</option>
                      <option
                          value="8.500">8.500</option>
                      <option
                          value="8.625">8.625</option>
                      <option
                          value="8.750">8.750</option>
                      <option
                          value="8.875">8.875</option>
                      <option
                          value="9.000">9.000</option>
                      <option
                          value="9.125">9.125</option>
                      <option
                          value="9.250">9.250</option>
                      <option
                          value="9.375">9.375</option>
                      <option
                          value="9.500">9.500</option>
                      <option
                          value="9.625">9.625</option>
                      <option
                          value="9.750">9.750</option>
                      <option
                          value="9.875">9.875</option>
                      <option
                          value="10.000">10.000</option>
                      <option
                          value="10.125">10.125</option>
                      <option
                          value="10.250">10.250</option>
                      <option
                          value="10.375">10.375</option>
                      <option
                          value="10.500">10.500</option>
                      <option
                          value="10.625">10.625</option>
                      <option
                          value="10.750">10.750</option>
                      <option
                          value="10.875">10.875</option>
                      <option
                          value="11.000">11.000</option>
                      <option
                          value="11.125">11.125</option>
                      <option
                          value="11.250">11.250</option>
                      <option
                          value="11.375">11.375</option>
                      <option
                          value="11.500">11.500</option>
                      <option
                          value="11.625">11.625</option>
                      <option
                          value="11.750">11.750</option>
                      <option
                          value="11.875">11.875</option>
                      <option
                          value="12.000">12.000</option>
                      <option
                          value="12.125">12.125</option>
                      <option
                          value="12.250">12.250</option>
                      <option
                          value="12.375">12.375</option>
                      <option
                          value="12.500">12.500</option>
                      <option
                          value="12.625">12.625</option>
                      <option
                          value="12.750">12.750</option>
                      <option
                          value="12.875">12.875</option>
                      <option
                          value="13.000">13.000</option>
                      <option
                          value="13.125">13.125</option>
                      <option
                          value="13.250">13.250</option>
                      <option
                          value="13.375">13.375</option>
                      <option
                          value="13.500">13.500</option>
                      <option
                          value="13.625">13.625</option>
                      <option
                          value="13.750">13.750</option>
                      <option
                          value="13.875">13.875</option>
                      <option
                          value="14.000">14.000</option>
                    </select></td>
                </tr>
                <tr>
                  <td colspan="2">Loan Amount:
                    <br> <input class="textbox"
                        maxlength="15" size="15" name="loan_amount"
id="loan_amount" ></td>
                  <td><label for="property_type">Property Type:</label>
                    <br> <select class="textbox"
                        name="property_type" id="property_type">
                      <option value="">Select One</option>
                      <option value="" selected>----------</option>
                      <option value="interest_only">Interest Only</option>
                      <option value="option_arm">Option Arm</option>
                    </select></td>
                </tr>
                <tr>
                  <td colspan="2"><label for="down_payment">Down
Payment:</label>
                    <br> <input
                        class="textbox" maxlength="15" size="15"
name="down_payment" id="down_payment" ></td>
                  <td><label for="property_value">Property
Value/Purchase Price:</label>
                    <br> <input
                        class="textbox" maxlength="25" size="25"
name="Input" ></td>
                </tr>
                <tr>
                  <td colspan="2"><label
for="property_address">Property Address:</label>
                    <br> <input
                        class="textbox" maxlength="35" size="35"
name="property_address" id="property_address" ></td>
                </tr>
                <tr>
                  <td colspan="3"><label for="City_State_zip">City, State, Zip
                    Code:</label>
                    <br> <input
                        class="textbox" maxlength="25" size="25"
name="city" id="city" >
                    &nbsp; <input
                        class="textbox" maxlength="10" size="10"
name="state" id="state" >