Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a .xxx via PHP

Status
Not open for further replies.

cadbilbao

Programmer
Apr 9, 2001
233
ES
Hi!

I've got installed an Apache+PHP server on my LinuxBox.

I want to create a 'myname.foo' file, but generated via PHP.

I mean:

----//----

<?php

header(&quot;Content-type: FooType&quot;);
....

-----//-----

I modify my 'httpd.conf' file, and insert:
AddType FooType .foo

But when browsing 'myname.foo', this is not generated, I only get the '<?php ....'.

How can I tell Apache to generate .foo files by using PHP?

Regards,
 
If you are trying to configure Apache to parse files through PHP with an extension of say .foo you use:

AddType applicaton/x-httpd-php .foo

Then restart Apache and try to execute your script


If you are trying to create a custom mime-type extension, remember that the mime-type has to be recognized and registered (for example, application/pdf). So we can do this:

AddType application/pdf .foo

Now if I restart Apache and go to (and if I have adobe acrobat installed and the plugin for browser integration turned on) my browser will attempt to open the file as an acrobat file.

If you don't use Apache to set these, you will have to use the header() to tell the server how to handle the output from the script:

<?php
Header( &quot;Content-type: image/gif&quot;);
Header( &quot;Expires: Wed, 11 Nov 1998 11:11:11 GMT&quot;);
Header( &quot;Cache-Control: no-cache&quot;);
Header( &quot;Cache-Control: must-revalidate&quot;);

// if # is in front of the hex-string
$rgb = str_replace(&quot;#&quot;, &quot;&quot;, $c);

$r = hexdec(substr ($rgb, 0,2));
$g = hexdec(substr ($rgb, 2,2));
$b = hexdec(substr ($rgb, 4,2));

if($c){
printf (&quot;%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c&quot;,71,73,70,56,57,97,1,0,1,0,128,0,0,$r,$g,$b,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
}
else{
printf (&quot;%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%&quot;,71,73,70,56,57,97,1,0,1,0,128,255,0,0,0,0,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
}

?>

in this sample, you would save the above script and then execute it:


When I do this, a 1x1 black pixel will appear

Chad.
ICQ: 54380631
 
Quick note:

If you are not the server admin, and do not have access to restart the server, the line

AddType applicaton/x-httpd-php .foo

can be added to your .htaccess file and acheive the same results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top