“Save As” Dialog Box for Streaming File

To download files using a “Save As” dialog box try this code:

        Select Case FileExt
            Case “gif” ContentType = “image/gif”
            Case “tif” ContentType = “image/tiff”
            Case “jpg” ContentType = “image/jpeg”
            Case “pdf” ContentType = “application/pdf”
            Case “avi” ContentType = “video/x-msvideo”
            Case “mp3” ContentType = “audio/mpeg”
            Case “mpg” ContentType = “video/mpeg”
            Case “wav” ContentType = “audio/wav”
            Case “rar” ContentType = “application/x-rar-compressed”
            Case “zip” ContentType = “application/x-zip-compressed”
            Case “exe” ContentType = “application/x-msdownload”
            Case Else
             ‘ FilePath = “”
             ContentType = “application/x-msdownload”
        End Select

        Response.Clear
        Response.Buffer = False
        Dim adoStream
        Set adoStream = Server.CreateObject(“ADODB.Stream”)
        adoStream.Open()
        adoStream.Type = 1
        adoStream.LoadFromFile(FilePath + “/” + FileName)
        Response.AddHeader “Content-Disposition”, “attachment;filename=” & Right(FileName,Len(FileName)-InStr(FileName,”/”))
        Response.ContentType = ContentType
        Response.BinaryWrite(adoStream.Read())
        adoStream.Close
        Set adoStream = Nothing
        Response.End

The ASP buffering limit is about 4 megs. Files larger than that will give an error like this:

   “Response Buffer to exceed its configured limit”

To stream out files larger than 4 Meg you can increase the “AspBufferingLimit” value. Edit the MetaBase.xml file in the C:\WINDOWS\system32\inetsrv folder. The default value is 4194304. Check the “Enable Direct Metabase Edits” check box before editing this file and you will not need to stop and start the WWW service.

PHP 5 on Windows 2003 Server (IIS)

Here are my notes on setting up PHP 5.1.6 on a Windows 2003 server (SBS).

  1. Must have “c:/php/” in system PATH environment variables (must reboot server when changing).
  2. In IIS under Web Service Extentions must have c:\php\php5isapi.dll Enabled.
  3. In IIS under the default web site (and particular web site to use PHP), configure the Application extention for .php to have path “C:\PHP\php5isapi.dll”, limit verbs to “GET,HEAD,POST”.
  4. Put php.ini in the c:\windows directory. The ISAPI extention didn’t find the ini file in the php directory.
  5. Add IUSR_Machinename to the PHP directory.
  6. In the php.ini file, hard code the extentions path, i.e. extension_dir = “c:/php/ext/”.
  7. In the php.ini file, comment out the doc_root line, i.e. ‘;doc_root = “c:\Inetpub\wwwroot” ‘.
  8. In the php.ini file, hard code the path to the session.save_path, i.e. ‘session.save_path = “c:/php/sessiondata” ‘.
  9. Add IUSR_Machinename write permission to the sessiondata and file upload folders.
  10. In the php.ini folder, turn display_errors = On to see error information.
  11. Always restart IIS when making changes to the php.ini file.
  12. Use this function to test PHP:
    <?php
    phpinfo();
    ?>
  13. Run PHP from a dos prompt at the PHP folder to view any missing DLL’s. This does not test the ISAPI extention pathing though.

Hope this helps someone. I found the PHP documentaion to be a bit lacking. At the time of this writing there was not an installer for PHP 5 (at least that I could find). I was also upgrading from PHP 4 (cgi) and MySQL 4 to MySQL 5.

Some of the trouble I encountered was a completely white screen (no error message at all), MySQL would not load into PHP, and “No input file specified” (doc_root).