PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/popups/uploadimage.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 179 lines | 124 code | 32 blank | 23 comment | 49 complexity | d21f0c09e2e723983211a6dd4a232e62 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: uploadimage.php 10002 2008-02-08 10:56:57Z willebil $
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. // Set flag that this is a parent file
  14. define( "_VALID_MOS", 1 );
  15. /** security check */
  16. require( '../includes/auth.php' );
  17. include_once ( $mosConfig_absolute_path . '/language/' . $mosConfig_lang . '.php' );
  18. /*
  19. * Stops file upload below /images/stories directory
  20. * Added 1.0.11
  21. */
  22. function limitDirectory( &$directory ) {
  23. if ( strpos($directory, '../') !== false ) {
  24. $directory = str_replace('../', '', $directory);
  25. }
  26. if ( strpos($directory, '..\\') !== false ) {
  27. $directory = str_replace('..\\', '', $directory);
  28. }
  29. if ( strpos($directory, ':') !== false ) {
  30. $directory = str_replace(':', '', $directory);
  31. }
  32. return $directory;
  33. }
  34. // limit access to functionality
  35. $option = strval( mosGetParam( $_SESSION, 'option', '' ) );
  36. $task = strval( mosGetParam( $_SESSION, 'task', '' ) );
  37. switch ($option) {
  38. case 'com_banners':
  39. break;
  40. case 'com_categories':
  41. case 'com_content':
  42. case 'com_sections':
  43. case 'com_typedcontent':
  44. if ( $task != 'edit' && $task != 'editA' && $task != 'new' ) {
  45. echo _NOT_AUTH;
  46. return;
  47. }
  48. break;
  49. default:
  50. echo _NOT_AUTH;
  51. return;
  52. break;
  53. }
  54. // mainframe is an API workhorse, lots of 'core' interaction routines
  55. $mainframe = new mosMainFrame( $database, $option, $mosConfig_absolute_path, true );
  56. $directory = mosGetParam( $_REQUEST, 'directory', '');
  57. $css = mosGetParam( $_REQUEST, 't','');
  58. $media_path = $mosConfig_absolute_path.'/media/';
  59. $userfile2 = (isset($_FILES['userfile']['tmp_name']) ? $_FILES['userfile']['tmp_name'] : "");
  60. $userfile_name = (isset($_FILES['userfile']['name']) ? $_FILES['userfile']['name'] : "");
  61. limitDirectory( $directory );
  62. // check to see if directory exists
  63. if ( $directory != 'banners' && $directory != '' && !is_dir($mosConfig_absolute_path .'/images/stories/'. $directory)) {
  64. $directory = '';
  65. }
  66. $action = "window.location.href = 'uploadimage.php?directory=$directory&amp;t=$css'";
  67. if (isset($_FILES['userfile'])) {
  68. if ($directory == 'banners') {
  69. $base_Dir = "../../images/banners/";
  70. } else if ( $directory != '' ) {
  71. $base_Dir = '../../images/stories/'. $directory;
  72. if (!is_dir($mosConfig_absolute_path .'/images/stories/'. $directory)) {
  73. $base_Dir = '../../images/stories/';
  74. $directory = '';
  75. }
  76. } else {
  77. $base_Dir = '../../images/stories/';
  78. }
  79. if (empty($userfile_name)) {
  80. mosErrorAlert("Please select an image to upload", $action);
  81. }
  82. $filename = split("\.", $userfile_name);
  83. if (eregi("[^0-9a-zA-Z_]", $filename[0])) {
  84. mosErrorAlert('File must only contain alphanumeric characters and no spaces please.', $action );
  85. }
  86. if (file_exists($base_Dir.$userfile_name)) {
  87. mosErrorAlert('Image '.$userfile_name.' already exists.', $action );
  88. }
  89. if ((strcasecmp(substr($userfile_name,-4),'.gif')) && (strcasecmp(substr($userfile_name,-4),'.jpg')) && (strcasecmp(substr($userfile_name,-4),'.png')) && (strcasecmp(substr($userfile_name,-4),'.bmp')) &&(strcasecmp(substr($userfile_name,-4),'.doc')) && (strcasecmp(substr($userfile_name,-4),'.xls')) && (strcasecmp(substr($userfile_name,-4),'.ppt')) && (strcasecmp(substr($userfile_name,-4),'.swf')) && (strcasecmp(substr($userfile_name,-4),'.pdf'))) {
  90. mosErrorAlert('The file must be gif, png, jpg, bmp, swf, doc, xls or ppt', $action);
  91. }
  92. if (eregi('.pdf', $userfile_name) || eregi('.doc', $userfile_name) || eregi('.xls', $userfile_name) || eregi('.ppt', $userfile_name)) {
  93. if (!move_uploaded_file ($_FILES['userfile']['tmp_name'],$media_path.$_FILES['userfile']['name']) || !mosChmod($media_path.$_FILES['userfile']['name'])) {
  94. mosErrorAlert('Upload of '.$userfile_name.' failed', $action);
  95. } else {
  96. mosErrorAlert('Upload of '.$userfile_name.' to '.$base_Dir.' successful', "window.close()");
  97. }
  98. } elseif (!move_uploaded_file ($_FILES['userfile']['tmp_name'],$base_Dir.$_FILES['userfile']['name']) || !mosChmod($base_Dir.$_FILES['userfile']['name'])) {
  99. mosErrorAlert('Upload of '.$userfile_name.' failed', $action);
  100. } else {
  101. mosErrorAlert('Upload of '.$userfile_name.' to '.$base_Dir.' successful', "window.close()");
  102. }
  103. echo $base_Dir.$_FILES['userfile']['name'];
  104. }
  105. // css file handling
  106. // check to see if template exists
  107. if ( $css != '' && !is_dir($mosConfig_absolute_path .'/administrator/templates/'. $css .'/css/template_css.css' )) {
  108. $css = 'joomla_admin';
  109. } else if ( $css == '' ) {
  110. $css = 'joomla_admin';
  111. }
  112. $iso = split( '=', _ISO );
  113. // xml prolog
  114. echo '<?xml version="1.0" encoding="'. $iso[1] .'"?' .'>';
  115. ?>
  116. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  117. <html xmlns="http://www.w3.org/1999/xhtml">
  118. <head>
  119. <title>Upload a file</title>
  120. <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ?>" />
  121. </head>
  122. <body>
  123. <link rel="stylesheet" href="../templates/<?php echo $css; ?>/css/template_css.css" type="text/css" />
  124. <form method="post" action="uploadimage.php" enctype="multipart/form-data" name="filename">
  125. <table class="adminform">
  126. <tr>
  127. <th class="title">
  128. File Upload : <?php echo $directory; ?>
  129. </th>
  130. </tr>
  131. <tr>
  132. <td align="center">
  133. <input class="inputbox" name="userfile" type="file" />
  134. </td>
  135. </tr>
  136. <tr>
  137. <td>
  138. <input class="button" type="submit" value="Upload" name="fileupload" />
  139. Max size = <?php echo ini_get( 'post_max_size' );?>
  140. </td>
  141. </tr>
  142. </table>
  143. <input type="hidden" name="directory" value="<?php echo $directory;?>" />
  144. <input type="hidden" name="<?php echo josSpoofValue(); ?>" value="1" />
  145. </form>
  146. </body>
  147. </html>