Adding template for error box.
[squirrelmail.git] / plugins / newmail / loadfile.php
CommitLineData
dbc7cd0a 1<?php
4b4abf93 2
dbc7cd0a 3/**
4 * SquirrelMail NewMail plugin
5 *
6 * Script loads user's media file.
4b4abf93 7 *
47ccfad4 8 * @copyright &copy; 2001-2006 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
dbc7cd0a 10 * @version $Id$
11 * @package plugins
fb883255 12 * @subpackage newmail
dbc7cd0a 13 */
14
197562c9 15/**
f8a1ed5a 16 * define SM_PATH
197562c9 17 * @ignore
18 */
dbc7cd0a 19define('SM_PATH','../../');
20
21/** Load squirrelmail functions */
22include_once(SM_PATH . 'include/validate.php');
23/** Load plugin functions */
24include_once(SM_PATH . 'plugins/newmail/functions.php');
25
26sqgetGlobalVar('username',$username,SQ_SESSION);
27global $data_dir;
28
29$media = getPref($data_dir,$username,'newmail_media', '(none)');
fb883255 30// get other prefs
31$newmail_userfile_type=getPref($data_dir,$username,'newmail_userfile_type',false);
f8a1ed5a 32
fb883255 33$newmail_userfile_location=getHashedFile($username, $data_dir, $username . '.sound');
dbc7cd0a 34
f9710f76 35if ($newmail_uploadsounds && $newmail_userfile_type!=false && file_exists($newmail_userfile_location)) {
fb883255 36 // open media file
37 $newmail_userfile_handle = fopen($newmail_userfile_location,'rb');
38 if ($newmail_userfile_handle) {
39 $newmail_userfile_filesize = filesize($newmail_userfile_location);
40 $newmail_userfile_contents = fread($newmail_userfile_handle,$newmail_userfile_filesize);
41 fclose ($newmail_userfile_handle);
dbc7cd0a 42
fb883255 43 // user prefs use only integer values to store file type
44 switch($newmail_userfile_type) {
45 case SM_NEWMAIL_FILETYPE_WAV:
46 // wav file
47 $newmail_userfile_contenttype='audio/x-wav';
48 break;
49 case SM_NEWMAIL_FILETYPE_MP3:
50 // mp3 file
51 $newmail_userfile_contenttype='audio/mpeg';
52 break;
53 case SM_NEWMAIL_FILETYPE_OGG:
54 // ogg file
55 $newmail_userfile_contenttype='application/ogg';
56 break;
57 case SM_NEWMAIL_FILETYPE_SWF:
58 // flash file
59 $newmail_userfile_contenttype='application/x-shockwave-flash';
60 break;
61 case SM_NEWMAIL_FILETYPE_SVG:
62 // svg file
63 $newmail_userfile_contenttype='image/svg+xml';
64 break;
65 default:
66 // none of above
67 $newmail_userfile_contenttype='unknown';
68 }
dbc7cd0a 69
fb883255 70 // make sure that media file is in correct format
71 $newmail_userfile_extension=newmail_detect_filetype($newmail_userfile_contents,$newmail_userfile_contenttype);
dbc7cd0a 72
fb883255 73 // last check before sending file contents to browser.
74 if ($newmail_userfile_extension!=false) {
75 $newmail_send_filename='mediafile.' . $newmail_userfile_extension;
76 header ('Content-Disposition: inline; filename="' . $newmail_send_filename . '"');
77 header('Content-Type: "' . $newmail_userfile_contenttype .'"; ' .
78 'name="' . $newmail_send_filename . '"');
79 header('Content-Length: ' . $newmail_userfile_filesize );
80 echo $newmail_userfile_contents;
81 exit;
82 } // file type detection failed
83 } // failed to open userfile
84} // userfile is missing or preferences don't store file type.
dbc7cd0a 85// maybe we should send some error code
86?>