Source for file class.flexupload.inc.php

Documentation is available at class.flexupload.inc.php

  1. <?php
  2. /**
  3. * class.flexupload.inc.php
  4. *
  5. * PHP-Class for easy implementation of FlexUpload in your own scripts
  6. *
  7. * Copyright (C) 2007 SPLINELAB, Mirko Schaal
  8. * http://www.splinelab.de/flexupload/
  9. *
  10. * All rights reserved
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option)
  15. * any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful, but WITHOUT
  18. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. * FITNESS FOR A PARTICULAR PURPOSE.
  20. * See the GNU General Public License for more details.
  21. *
  22. * The GNU General Public License can be found at
  23. * http://www.gnu.org/copyleft/gpl.html.
  24. * A copy is found in the textfile GPL and important notices to the license from
  25. * the author is found in the LICENSE file distributed with the program.
  26. *
  27. * This copyright notice MUST APPEAR in all copies of the program!
  28. *
  29. * @version 1.0
  30. * @author Mirko Schaal <ms@splinelab.com>
  31. * @package FlexUpload
  32. * @subpackage core
  33. */
  34.  
  35. /**
  36. * PHP-Class for easy implementation of FlexUpload in your own scripts
  37. * @version 1.0
  38. * @author Mirko Schaal <ms@splinelab.com>
  39. * @package FlexUpload
  40. * @subpackage core
  41. */
  42. class FlexUpload {
  43.  
  44. /**
  45. * the url to the upload script
  46. * @access private
  47. * @var String
  48. */
  49. var $_postURL;
  50.  
  51. /**
  52. * the path to flexupload.swf
  53. * @access private
  54. * @var String
  55. */
  56. var $_pathToSWF;
  57.  
  58. /**
  59. * maximal allowed filesize
  60. * @access private
  61. * @var integer
  62. */
  63. var $_maxFileSize;
  64.  
  65. /**
  66. * maximal allowed files
  67. * @access private
  68. * @var integer
  69. */
  70. var $_maxFiles;
  71.  
  72. /**
  73. * allowed file extensions
  74. * @access private
  75. * @var String
  76. */
  77. var $_fileExtensions;
  78.  
  79. /**
  80. * the locale
  81. * @access private
  82. * @var String
  83. */
  84. var $_locale;
  85.  
  86. /**
  87. * the width of the flash movie
  88. * @access private
  89. * @var integer
  90. */
  91. var $_width;
  92.  
  93. /**
  94. * the height of the flash movie
  95. * @access private
  96. * @var integer
  97. */
  98. var $_height;
  99.  
  100. /**
  101. * message to show when using SWFObject an Flash-Plugin is missing or wrong version
  102. * @access private
  103. * @var string
  104. */
  105. var $_noFlashMsg = '<p>You may not have everything you need to use Flexupload.<br />Please install or update "Flash Player" which is available for free at the <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Adobe website</a>.<br />Please also make sure you have JavaScript enabled.</p>';
  106.  
  107. /**
  108. * path to the SWFObject Script
  109. * @access private
  110. * @var string
  111. */
  112. var $_pathToSWFObject = 'js/';
  113.  
  114. /**
  115. * Constructor
  116. *
  117. * @param String $postURL see {@link setPostURL}
  118. * @param String $pathToSWF see {@link setPathToSWF}
  119. * @param String $width see {@link setWidth}
  120. * @param String $height see {@link setHeight}
  121. * @param String $maxFileSize see {@link setMaxFileSize}
  122. * @param String $maxFiles see {@link setMaxFiles}
  123. * @param String $fileExtensions see {@link setFileExtensions}
  124. * @param String $locale see {@link setLocale}
  125. */
  126. function FlexUpload($postURL, $pathToSWF='', $width=500, $height=300, $maxFileSize=2097152,
  127. $maxFiles=100, $fileExtensions='*.gif;*.jpg;*.jpeg;*.png', $locale='' ) {
  128. $this->_postURL = $postURL;
  129. $this->_pathToSWF = $pathToSWF;
  130. $this->_width = $width;
  131. $this->_height = $height;
  132. $this->_maxFileSize = $maxFileSize;
  133. $this->_maxFiles = $maxFiles;
  134. $this->_fileExtensions = $fileExtensions;
  135. $this->_locale = $locale;
  136. }
  137.  
  138. /**
  139. * set the postURL parameter
  140. *
  141. * the postURL have to be a full url incl. protocol
  142. * e.g. "http://localhost/upload.php"
  143. *
  144. * @param String $postURL
  145. */
  146. function setPostURL($postURL) {
  147. $this->_postURL = $postURL;
  148. }
  149.  
  150. /**
  151. * set the path to the SWF file
  152. *
  153. * Give an absolute or relative path to flexupload.swf or an empty string if flexupload.swf is in the same
  154. * directory like the php-file using this class.
  155. *
  156. * default is empty string
  157. *
  158. * @param String $path
  159. */
  160. function setPathToSWF($path) {
  161. $this->_pathToSWF = $path;
  162. }
  163.  
  164. /**
  165. * set the width of the application
  166. *
  167. * the applet automatically scales to this width
  168. *
  169. * default is 500
  170. *
  171. * @param integer $w
  172. */
  173. function setWidth($w) {
  174. $this->_width = $w;
  175. }
  176.  
  177. /**
  178. * set the height of the application
  179. *
  180. * the applet automatically scales to this height
  181. *
  182. * default is 300
  183. *
  184. * @param integer $h
  185. */
  186. function setHeight($h) {
  187. $this->_height = $h;
  188. }
  189.  
  190. /**
  191. * set the maximum filesize (in bytes) allowed to upload
  192. *
  193. * default is 2MB (2097152 bytes)
  194. *
  195. * @param integer $mfs
  196. */
  197. function setMaxFileSize($mfs) {
  198. $this->_maxFileSize = intval($mfs);
  199. }
  200.  
  201. /**
  202. * set the maximum of files to upload at once
  203. *
  204. * set this to -1 for no limit
  205. *
  206. * default is 100
  207. *
  208. * @param integer $mf
  209. */
  210. function setMaxFiles($mf) {
  211. $this->_maxFiles = intval($mf);
  212. }
  213.  
  214. /**
  215. * set the allowed file extensions separated by semicolons (;)
  216. *
  217. * set to empty string for all files
  218. *
  219. * default is "*.gif;*.jpg;*.jpeg;*.png"
  220. *
  221. * @param String $fe
  222. */
  223. function setFileExtensions($fe) {
  224. $this->_fileExtensions = $fe;
  225. }
  226.  
  227.  
  228. /**
  229. * set the language file for the application
  230. *
  231. * e.g "locale/de.xml" or "http://www.example.com/flexupload/locale/de.xml"
  232. * set en empty string to use the default locale (english)
  233. *
  234. * default is ""
  235. *
  236. * @param integer $l
  237. */
  238. function setLocale($l) {
  239. $this->_locale = $l;
  240. }
  241.  
  242.  
  243. /**
  244. * set the message to show when using SWFObject an flash plugin is not installed or wrong version
  245. *
  246. * default is "You may not have everything you need ..."
  247. *
  248. * @param string $msg
  249. */
  250. function setNoFlashMessage($msg)
  251. {
  252. $this->_noFlashMsg = $msg;
  253. }
  254.  
  255. /**
  256. * set the path to the SWFObject JavaScript script
  257. *
  258. * default is "js/"
  259. *
  260. * @param string $path
  261. */
  262. function setPathToSWFObject($path)
  263. {
  264. $this->_pathToSWFObject = $path;
  265. }
  266.  
  267. /**
  268. * get the HTML code for implementing flexupload
  269. *
  270. * see {@link printHTML}
  271. *
  272. * @param Boolean $useSWFObject Use the SWFObject script for output (recommended)
  273. * @param String $divId a unique id for the SWFObject <div>-Tag
  274. * @param Boolean $includeSWFObject Include the swfobject.js in the code (if you don't set this to true you have to manually include swfobject.js) Also note: if you have more than one flexupload in one page you should include the javascript in the first one only!
  275. *
  276. * @return String $HTML the html code for the application
  277. */
  278. function getHTML($useSWFObject=true, $divId='flexupload', $includeSWFObject=true)
  279. {
  280. $params = '?postURL='.rawurlencode($this->_postURL);
  281. $params .= '&maxFileSize='.$this->_maxFileSize;
  282. $params .= '&maxFiles='.$this->_maxFiles;
  283. $params .= '&fileExtensions='.rawurlencode($this->_fileExtensions);
  284. $params .= '&locale='.rawurlencode($this->_locale);
  285.  
  286. $content = '';
  287.  
  288. if ($useSWFObject) {
  289. if ($includeSWFObject)
  290. $content .= '<script type="text/javascript" src="'.$this->_pathToSWFObject.'swfobject.js"></script>';
  291. $content .= '<div id="'.$divId.'">'.$this->_noFlashMsg."\n";
  292. $content .= '<script type="text/javascript">'."\n";
  293. $content .= '// <![CDATA['."\n";
  294. $content .= 'var obj_'.$divId.' = new SWFObject("'.$this->_pathToSWF.'flexupload.swf'.$params.'", "'.$divId.'", "'.$this->_width.'", "'.$this->_height.'", "9", "#869ca7");'."\n";
  295. $content .= 'obj_'.$divId.'.addParam("scale", "noscale");'."\n";
  296. $content .= 'obj_'.$divId.'.addParam("salign", "lt");'."\n";
  297. $content .= 'obj_'.$divId.'.addParam("menu", "false");'."\n";
  298. $content .= 'obj_'.$divId.'.addParam("quality", "best");'."\n";
  299. $content .= 'obj_'.$divId.'.addParam("wmode", "transparent");'."\n";
  300. $content .= 'obj_'.$divId.'.write("'.$divId.'");'."\n";
  301. $content .= '// ]]>'."\n";
  302. $content .= '</script>'."\n";
  303. } else {
  304. $content = '
  305. <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="flexupload" width="'.$this->_width.'" height="'.$this->_height.'" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
  306. <param name="movie" value="'.$this->_pathToSWF.'flexupload.swf'.$params.'" />
  307. <param name="quality" value="best" />
  308. <param name="bgcolor" value="#869ca7" />
  309. <param name="wmode" value="transparent" />
  310. <param name="menu" value="false" />
  311. <param name="scale" value="noscale" />
  312. <param name="salign" value="lt" />
  313. <embed src="'.$this->_pathToSWF.'flexupload.swf'.$params.'" quality="best" bgcolor="#869ca7"
  314. width="'.$this->_width.'" height="'.$this->_height.'" name="flexupload" align="middle" play="true" loop="false"
  315. wmode="transparent"
  316. menu="false"
  317. scale="noscale"
  318. salign="lt"
  319. type="application/x-shockwave-flash"
  320. pluginspage="http://www.adobe.com/go/getflashplayer">
  321. </embed>
  322. </object>';
  323. }
  324. return $content;
  325. }
  326.  
  327. /**
  328. * prints the HTML code for flexupload to screen
  329. *
  330. * see {@link getHTML}
  331. *
  332. * @param Boolean $useSWFObject Use the SWFObject script for output (recommended)
  333. * @param String $divId a unique id for the SWFObject <div>-Tag
  334. * @param Boolean $includeSWFObject Include the swfobject.js in the code (if you don't set this to true you have to manually include swfobject.js) Also note: if you have more than one flexupload in one page you should include the javascript in the first one only!
  335. */
  336. function printHTML($useSWFObject=true, $divId='flexupload', $includeSWFObject=true) {
  337. echo $this->getHTML($useSWFObject, $divId, $includeSWFObject);
  338. }
  339. }
  340. ?>

Documentation generated on Mon, 18 Jun 2007 21:42:50 +0200 by phpDocumentor 1.3.0RC3