Browser troubles (1.4.2)

Please mention which Dokeos version you are using
This is the forum for bugs concerning versions earlier than Dokeos 1.6

Browser troubles (1.4.2)

Postby roan » Tue Feb 10, 2004 9:40 am

Something that has been annoying some users here for a long time... it's perhaps not a Claroline bug, it's browser-related.

When downloading a document, sometimes the filename becomes not that of the document itself but "document_goto.php". Some people report that the problem occurs with Konqueror and Mozilla, not with Opera en Internet Explorer.

And a perhaps related issue: there is a long list of file extensions --> mimetypes, e.g. "mp2" => "audio/mpeg" but it's never enough, people have complained about this "I click on maple files, and I see strange symbols / I get document_goto.php..."

Here is some code from Jan Bols, that maybe solves theses issues he used it in the dropbox, haven't had the time to look at it yet.
Code: Select all
<?php
function send_file_to_client($filename)
{
   global $HTTP_USER_AGENT,$_SERVER;
   
   if(!file_exists($filename)) return false;

   $content_type=get_mime_type($filename);

   if(isset($content_type))
   {
      header( "Content-type: $content_type\n");
      header( "Content-Disposition: inline; filename=\"$filename\"");
   }
   else
   {
      header( "Content-type: application/octet-stream\n");
      if(preg_match("/MSIE 5.5/",$HTTP_USER_AGENT))
         header("Content-Disposition: filename=\"$filename\"\n");
      else header("Content-Disposition: attachment;
         filename=\"$filename\"\n");
   }
   if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE'))
   {
      header( "Pragma: \n");
      header( "Cache-Control: \n");
      header( "Cache-Control: public\n"); // IE cannot download from sessions without a cache
   }

   header("Content-Description: \"" .
   trim(htmlentities($filename))."\"\n");
   header("Content-transfer-encoding: binary\n");
   header("Content-length: ".filesize($filename)."\n" );

   $fp=fopen("$filename","r");
   fpassthru($fp);
   return true;
}

function get_mime_type($filename)
{
   $f=array(
       "ez" => "application/andrew-inset",
       "hqx" => "application/mac-binhex40",
       "cpt" => "application/mac-compactpro",
       "doc" => "application/msword",
       "bin" => "application/octet-stream",
       "dms" => "application/octet-stream",
       "lha" => "application/octet-stream",
       "lzh" => "application/octet-stream",
       "exe" => "application/octet-stream",
       "class" => "application/octet-stream",
       "so" => "application/octet-stream",
       "dll" => "application/octet-stream",
       "oda" => "application/oda",
       "pdf" => "application/pdf",
       "ai" => "application/postscript",
       "eps" => "application/postscript",
       "ps" => "application/postscript",
       "smi" => "application/smil",
       "smil" => "application/smil",
       "wbxml" => "application/vnd.wap.wbxml",
       "wmlc" => "application/vnd.wap.wmlc",
       "wmlsc" => "application/vnd.wap.wmlscriptc",
       "bcpio" => "application/x-bcpio",
       "vcd" => "application/x-cdlink",
       "pgn" => "application/x-chess-pgn",
       "cpio" => "application/x-cpio",
       "csh" => "application/x-csh",
       "dcr" => "application/x-director",
       "dir" => "application/x-director",
       "dxr" => "application/x-director",
       "dvi" => "application/x-dvi",
       "spl" => "application/x-futuresplash",
       "gtar" => "application/x-gtar",
       "hdf" => "application/x-hdf",
       "js" => "application/x-javascript",
       "skp" => "application/x-koan",
       "skd" => "application/x-koan",
       "skt" => "application/x-koan",
       "skm" => "application/x-koan",
       "latex" => "application/x-latex",
       "nc" => "application/x-netcdf",
       "cdf" => "application/x-netcdf",
       "sh" => "application/x-sh",
       "shar" => "application/x-shar",
       "swf" => "application/x-shockwave-flash",
       "sit" => "application/x-stuffit",
       "sv4cpio" => "application/x-sv4cpio",
       "sv4crc" => "application/x-sv4crc",
       "tar" => "application/x-tar",
       "tcl" => "application/x-tcl",
       "tex" => "application/x-tex",
       "texinfo" => "application/x-texinfo",
       "texi" => "application/x-texinfo",
       "t" => "application/x-troff",
       "tr" => "application/x-troff",
       "roff" => "application/x-troff",
       "man" => "application/x-troff-man",
       "me" => "application/x-troff-me",
       "ms" => "application/x-troff-ms",
       "ustar" => "application/x-ustar",
       "src" => "application/x-wais-source",
       "xhtml" => "application/xhtml+xml",
       "xht" => "application/xhtml+xml",
       "zip" => "application/zip",
       "au" => "audio/basic",
       "snd" => "audio/basic",
       "mid" => "audio/midi",
       "midi" => "audio/midi",
       "kar" => "audio/midi",
       "mpga" => "audio/mpeg",
       "mp2" => "audio/mpeg",
       "mp3" => "audio/mpeg",
       "aif" => "audio/x-aiff",
       "aiff" => "audio/x-aiff",
       "aifc" => "audio/x-aiff",
       "m3u" => "audio/x-mpegurl",
       "ram" => "audio/x-pn-realaudio",
       "rm" => "audio/x-pn-realaudio",
       "rpm" => "audio/x-pn-realaudio-plugin",
       "ra" => "audio/x-realaudio",
       "wav" => "audio/x-wav",
       "pdb" => "chemical/x-pdb",
       "xyz" => "chemical/x-xyz",
       "bmp" => "image/bmp",
       "gif" => "image/gif",
       "ief" => "image/ief",
       "jpeg" => "image/jpeg",
       "jpg" => "image/jpeg",
       "jpe" => "image/jpeg",
       "png" => "image/png",
       "tiff" => "image/tiff",
       "tif" => "image/tif",
       "djvu" => "image/vnd.djvu",
       "djv" => "image/vnd.djvu",
       "wbmp" => "image/vnd.wap.wbmp",
       "ras" => "image/x-cmu-raster",
       "pnm" => "image/x-portable-anymap",
       "pbm" => "image/x-portable-bitmap",
       "pgm" => "image/x-portable-graymap",
       "ppm" => "image/x-portable-pixmap",
       "rgb" => "image/x-rgb",
       "xbm" => "image/x-xbitmap",
       "xpm" => "image/x-xpixmap",
       "xwd" => "image/x-windowdump",
       "igs" => "model/iges",
       "iges" => "model/iges",
       "msh" => "model/mesh",
       "mesh" => "model/mesh",
       "silo" => "model/mesh",
       "wrl" => "model/vrml",
       "vrml" => "model/vrml",
       "css" => "text/css",
       "html" => "text/html",
       "htm" => "text/html",
       "asc" => "text/plain",
       "txt" => "text/plain",
       "rtx" => "text/richtext",
       "rtf" => "text/rtf",
       "sgml" => "text/sgml",
       "sgm" => "text/sgml",
       "tsv" => "text/tab-seperated-values",
       "wml" => "text/vnd.wap.wml",
       "wmls" => "text/vnd.wap.wmlscript",
       "etx" => "text/x-setext",
       "xml" => "text/xml",
       "xsl" => "text/xml",
       "mpeg" => "video/mpeg",
       "mpg" => "video/mpeg",
       "mpe" => "video/mpeg",
       "qt" => "video/quicktime",
       "mov" => "video/quicktime",
       "mxu" => "video/vnd.mpegurl",
       "avi" => "video/x-msvideo",
       "movie" => "video/x-sgi-movie",
       "ice" => "x-conference-xcooltalk"
     );
   $ext=get_file_extention($filename);
   if(isset($f[$ext])) return $f[$ext];
   return "application/octet-stream";
}

function get_file_extention($filename)
{
   $pos=strpos(strrev($filename),".");
   if($pos)
      $ext=substr($filename,strlen($filename)-$pos,$pos);
   else $ext="empty";
   return $ext;
}
?>
roan
 
Posts: 2192
Joined: Wed Dec 11, 2002 10:37 am
Location: Free University of Brussels, Belgium

Postby janbols » Tue Feb 10, 2004 10:31 am

First of all the code you showed Roan is not the most recent code from the dropbox. It's changed a bit:

Code: Select all
$mimetype = array(
'ez' => 'application/andrew-inset'
, 'hqx' => 'application/mac-binhex40'
, 'cpt' => 'application/mac-compactpro'
, 'doc' => 'application/msword'
, 'bin' => 'application/octet-stream'
, 'lha' => 'application/octet-stream'
, 'lzh' => 'application/octet-stream'
, 'exe' => 'application/octet-stream'
, 'class' => 'application/octet-stream'
, 'so' => 'application/octet-stream'
, 'dll' => 'application/octet-stream'
, 'oda' => 'application/oda'
, 'pdf' => 'application/pdf'
, 'ai' => 'application/postscript'
, 'eps' => 'application/postscript'
, 'ps' => 'application/postscript'
, 'smi' => 'application/smil'
, 'smil' => 'application/smil'
, 'xls' => 'application/vnd.ms-excel'
, 'ppt' => 'application/vnd.ms-powerpoint'
, 'wbxml' => 'application/vnd.wap.wbxml'
, 'wmlc' => 'application/vnd.wap.wmlc'
, 'wmlsc' => 'application/vnd.wap.wmlscriptc'
, 'bcpio' => 'application/x-bcpio'
, 'vcd' => 'application/x-cdlink'
, 'pgn' => 'application/x-chess-pgn'
, 'cpio' => 'application/x-cpio'
, 'csh' => 'application/x-csh'
, 'dcr' => 'application/x-director'
, 'dir' => 'application/x-director'
, 'dxr' => 'application/x-director'
, 'dvi' => 'application/x-dvi'
, 'spl' => 'application/x-futuresplash'
, 'gtar' => 'application/x-gtar'
, 'hdf' => 'application/x-hdf'
, 'js' => 'application/x-javascript'
, 'skp' => 'application/x-koan'
, 'skd' => 'application/x-koan'
, 'skt' => 'application/x-koan'
, 'skm' => 'application/x-koan'
, 'latex' => 'application/x-latex'
, 'nc' => 'application/x-netcdf'
, 'cdf' => 'application/x-netcdf'
, 'sh' => 'application/x-sh'
, 'shar' => 'application/x-shar'
, 'swf' => 'application/x-shockwave-flash'
, 'sit' => 'application/x-stuffit'
, 'sv4cpio' => 'application/x-sv4cpio'
, 'sv4crc' => 'application/x-sv4crc'
, 'tar' => 'application/x-tar'
, 'tcl' => 'application/x-tcl'
, 'tex' => 'application/x-tex'
, 'texinfo' => 'application/x-texinfo'
, 'texi' => 'application/x-texinfo'
, 't' => 'application/x-troff'
, 'tr' => 'application/x-troff'
, 'roff' => 'application/x-troff'
, 'man' => 'application/x-troff-man'
, 'me' => 'application/x-troff-me'
, 'ms' => 'application/x-troff-ms'
, 'ustar' => 'application/x-ustar'
, 'src' => 'application/x-wais-source'
, 'xhtml' => 'application/xhtml+xml'
, 'xht' => 'application/xhtml+xml'
, 'zip' => 'application/zip'
, 'au' => 'audio/basic'
, 'snd' => 'audio/basic'
, 'mid' => 'audio/midi'
, 'midi' => 'audio/midi'
, 'kar' => 'audio/midi'
, 'mpga' => 'audio/mpeg'
, 'mp2' => 'audio/mpeg'
, 'mp3' => 'audio/mpeg'
, 'aif' => 'audio/x-aiff'
, 'aiff' => 'audio/x-aiff'
, 'aifc' => 'audio/x-aiff'
, 'm3u' => 'audio/x-mpegurl'
, 'ram' => 'audio/x-pn-realaudio'
, 'rm' => 'audio/x-pn-realaudio'
, 'rpm' => 'audio/x-pn-realaudio-plugin'
, 'ra' => 'audio/x-realaudio'
, 'wav' => 'audio/x-wav'
, 'pdb' => 'chemical/x-pdb'
, 'xyz' => 'chemical/x-xyz'
, 'bmp' => 'image/bmp'
, 'gif' => 'image/gif'
, 'ief' => 'image/ief'
, 'jpeg' => 'image/jpeg'
, 'jpg' => 'image/jpeg'
, 'jpe' => 'image/jpeg'
, 'png' => 'image/png'
, 'tiff' => 'image/tiff'
, 'tif' => 'image/tiff'
, 'djvu' => 'image/vnd.djvu'
, 'djv' => 'image/vnd.djvu'
, 'wbmp' => 'image/vnd.wap.wbmp'
, 'ras' => 'image/x-cmu-raster'
, 'pnm' => 'image/x-portable-anymap'
, 'pbm' => 'image/x-portable-bitmap'
, 'pgm' => 'image/x-portable-graymap'
, 'ppm' => 'image/x-portable-pixmap'
, 'rgb' => 'image/x-rgb'
, 'xbm' => 'image/x-xbitmap'
, 'xpm' => 'image/x-xpixmap'
, 'xwd' => 'image/x-xwindowdump'
, 'igs' => 'model/iges'
, 'iges' => 'model/iges'
, 'msh' => 'model/mesh'
, 'mesh' => 'model/mesh'
, 'silo' => 'model/mesh'
, 'wrl' => 'model/vrml'
, 'vrml' => 'model/vrml'
, 'css' => 'text/css'
, 'html' => 'text/html'
, 'htm' => 'text/html'
, 'asc' => 'text/plain'
, 'txt' => 'text/plain'
, 'rtx' => 'text/richtext'
, 'rtf' => 'text/rtf'
, 'sgml' => 'text/sgml'
, 'sgm' => 'text/sgml'
, 'tsv' => 'text/tab-separated-values'
, 'wml' => 'text/vnd.wap.wml'
, 'wmls' => 'text/vnd.wap.wmlscript'
, 'etx' => 'text/x-setext'
, 'xml' => 'text/xml'
, 'xsl' => 'text/xml'
, 'mpeg' => 'video/mpeg'
, 'mpg' => 'video/mpeg'
, 'mpe' => 'video/mpeg'
, 'qt' => 'video/quicktime'
, 'mov' => 'video/quicktime'
, 'mxu' => 'video/vnd.mpegurl'
, 'avi' => 'video/x-msvideo'
, 'movie' => 'video/x-sgi-movie'
, 'ice' => 'x-conference/x-cooltalk'
    );

$fileparts = explode( '.', $file);
$filepartscount = count( $fileparts);

if ( ( $filepartscount > 1) && isset( $mimetype[$fileparts [$filepartscount - 1]]))
{
    // give hint to browser about filetype
    header( "Content-type: " . $mimetype[$fileparts [$filepartscount - 1]] . "\n");
    header( "Content-Disposition: inline; filename=$file\n");
}
else
{
   //no information about filetype: force a download dialog window in browser
   header( "Content-type: application/octet-stream\n");
   header( "Content-Disposition: inline; filename=$file\n");
}

header( "Pragma: \n");
header( "Cache-Control: \n");
header( "Cache-Control: public\n"); // IE cannot download from sessions without a cache

header( "Content-Description: " . trim( htmlentities( $file)) . "\n");
header( "Content-Transfer-Encoding: binary\n");
header( "Content-Length: " . filesize( $path)."\n" );


/**
* ========================================
* SEND FILE
* ========================================
*/
$fp = fopen( $path, "rb");
fpassthru( $fp);
exit( );


Differences are that IE5-specific code is removed because it makes no difference in other non IE5 browsers. The the list of mimetypes is taken from the list that is available in the apache installation.

And now about your 2 problems:
When downloading a document, sometimes the filename becomes not that of the document itself but "document_goto.php". Some people report that the problem occurs with Konqueror and Mozilla, not with Opera en Internet Explorer.

There's a difference when you click on the hyperlink or when you click with your right button of your mouse and choose 'save link as...'
1. Clicking directly on the link: This should give no problems as long as you send a header "Content-Disposition: xxx; filename=$file" where $file is the correct filename and xxx is either 'inline' or 'attachment'. I checked this in Opera 7.1, IE5, IE5.5, IE6, NN4.0, NN6.1, NN7.x, Mozilla 1.x, Konqueror 3.x, Galeon 1.2 and Galeon 1.3 and it gives the correct filename. NOTE: this does not always work in NN 6.0 but a lot of things don't always work in that release.

2. Clicking with the right button and choosing to save the link: Some browsers (NN4.x, NN6.x, Konqueror 3.0, Galeon 1.2, Galeon 1.3) show "save link as ...." as a menu option. Other browsers (IE, Opera, NN7.x) show "save TARGET link as ...". The difference is small but and in both cases the same file is sent to the client. However in the first case the default filename will be download.php, while in the second case it will be the correct filename as specified in the header "Content-Disposition: xxx; filename=$file".

I don't think there's anything you can do about this because it's browser related.


And now about your second issue:
And a perhaps related issue: there is a long list of file extensions --> mimetypes, e.g. "mp2" => "audio/mpeg" but it's never enough, people have complained about this "I click on maple files, and I see strange symbols / I get document_goto.php..."


This is not really related. If you have a file extension that's not in the list of known mime extensions the behaviour of the php download file should be to use the following header:
Code: Select all
header( "Content-type: application/octet-stream");

This will force the file to be downloaded on the client side instead of being shown inside the browser. In all the tests I did this did not come up as a problem as long as you use application/octet-stream as the defualt content type. However it's possible ofcourse that there are browsers out there where this does give a problem. If you have one, please tell me about it.

To conclude
1. Downloading a document through a download.php script can give problems in the filename not being the real name of the file in older mozilla-related browsers when a user clicks on the "save link as..."-menuoption.
2. Mime types are important to give the client browser a hint of how to handle the file. When there is no information about the file it should be sufficient to send a "Content-type: application/octet-stream" header to get a save-file-dialog on the client browser.

I hope the users of Dokeos can live with the limitations described in the first item, because the advantages of using a download.php script (no unauthorised access) are big + it's the only way I found the do this in php.

Note: if you have a browser that does give problems, please report it so it can be investigated further.

Jan Bols
janbols
 
Posts: 70
Joined: Mon Feb 17, 2003 9:20 am
Location: Gent

Postby Thomas » Tue Feb 10, 2004 10:41 am

Hello,

This problem has been created by the introduction of the tracking/statistics tool. Every time somebody downloads a file must be registered in the stats tool. So the link is not mydocument.html but document_goto.php

I don't know how to fix this. But it is important to check if Jan's code does not deactivate the stats tool that is required by so many organisations.

As concerning the never ending list of extensions and gifs associated, it is true that there is always something missing. However, I prefer the incompolete list to no list and standard icon. Hugue's solution was quite elegant in document.php : when no known mime type detected : white square.

Thomas
Thomas
 
Posts: 2173
Joined: Tue Mar 12, 2002 1:00 am
Location: Belgium


Return to Bugs older releases

Who is online

Users browsing this forum: No registered users and 0 guests