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