loadfile.php 3.0 KB

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