Archive for the ‘php’ Category

File Downloads with php in Internet Explorer

Wednesday, November 26th, 2008

For a web project with restricted access I wrote a script to download files via php. Basically I use rewrite rules to send the user to the php script, the script checks if the session is ok and sends the download (prepended by several headers) if the user has the proper permissions and the file is located in a directory that’s whitelisted.
Here’s the RewriteRule:

  1. RewriteRule ^/(downloads/.*) https://www.server.org/download.php?f=$1 [L,R,NC]

It worked fine except … Internet Explorer. In some cases, IE6 refused to save the file correctly. It just saved it with the name download.php and “unknown type”. Regardless of the type I sent along with Content-type and the name I sent with Content-Disposition.
(more…)

PEAR Mail_Mime::addHTMLImage() and Outlook 2002

Friday, October 24th, 2008

Yesterday I wasted hours trying to send emails with PEAR Mail. The inline images I added with Mail_Mime::addHTMLImage() just weren’t displayed in Outlook 2002 (aka Outlook XP). After hours of googling (bringing up a lot of snake oil tips) I found bug #13495 on PEAR: “urlencoded domainname in cid breaks mime mails in gmail”.

The cid (content id) is an ID that points to the different mime parts in multipart mails. As far as I know (I don’t know much about mime) it’s a unique ID followed by a domain. E.g.

15c0bf865f3884f33c22ff9e6109c9f3@leipold.ws

According to bug #13495 Gmail doesn’t like the @ in the cid. This has been fixed in Mail_Mime by urlencoding the cid.

Sadly Outlook 2002 didn’t cope with that. removing the urlencode helped showing the images.

Using exec on php/Windows

Saturday, September 13th, 2008

I tried to run a program with exec() but it just didn’t run. It was a program with several parameters, each parameter escaped with escapeshellarg().

It didn’t do anything, had no return value and no output. After putting a pair of extra quotes around the whole command it worked:

  1. $arg1 = escapeshellarg("first argument");
  2. $arg2 = escapeshellarg("second argument");
  3. $cmd = "C:\\do-something.bat $arg1 $arg2";
  4. exec("\"$cmd\"");

In the German php documentation I found the hint that exec() executes cmd /c with exec’s first parameter as argument. Therefore the whole command has to be quoted.

Installing php on IIS 6.0 – error 404

Friday, April 4th, 2008

I had trouble configuring php on IIS 6.0 – I did what the manual suggested to do but accessing a php-script resulted in an 404 error.

In IIS’s control panel (Internet Information Services (IIS) Manager) is a folder called “Web Service Extensions”. You have to add an extension and add php5isapi.dll (or php4isapi.dll I guess – haven’t tried php4) to the list of required files.

That should do the trick.

T_PAAMAYIM_NEKUDOTAYIM

Wednesday, May 9th, 2007

A colleague experienced a very strange error in PHP:

Parse error: syntax error, unexpected ‘[‘, expecting T_PAAMAYIM_NEKUDOTAYIM in script.php on line 123

We quickly found the error but it took a little googleing to find out what PHP meant by T_PAAMAYIM_NEKUDOTAYIM; it’s hebrew and means double-colon. It’s no bug but a kind of joke.

PHP 5.2.1 with mysql-Support

Sunday, February 11th, 2007

Today I tried to install PHP 5.2.1 with support for mysql. PHP worked fine, but the mysql-extension did not. The Apache-error-log said

PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\\Programme\\PHP\\ext\\php_mysql.dll’ – Das angegebene Modul wurde nicht gefunden.\r\n in Unknown on line 0

(In English something like “module not found”). Well, the file php_mysql.dll was in the folder where Apache pretended to search it. I used sysinternals’ filemon to check if there are any files which could not found during Apache’s startup. None. Later I had the great idea to use dependency walker to check if php_mysql.dll does need any files which aren’t there. And it did. A dll called dwmapi.dll (Microsoft Desktop Window Manager API) was missing. I googled and downloaded it. After putting it in the ext-directory PHP and MySQL worked fine.

Page optimized by WP Minify WordPress Plugin