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. * (C) 2007 SPLINELAB http://www.splinelab.com/flexupload/
  6. *
  7. * PHP-Class for easy implementation of FlexUpload in your own scripts
  8. *
  9. * @version 1.0
  10. * @author Mirko Schaal <ms@splinelab.com>
  11. * @package FlexUpload
  12. * @subpackage core
  13. */
  14.  
  15. /**
  16. * PHP-Class for easy implementation of FlexUpload in your own scripts
  17. * @version 1.0
  18. * @author Mirko Schaal <ms@splinelab.com>
  19. * @package FlexUpload
  20. * @subpackage core
  21. */
  22. class FlexUpload {
  23.  
  24. /**
  25. * the url to the upload script
  26. * @access private
  27. * @var String
  28. */
  29. var $_postURL;
  30.  
  31. /**
  32. * the path to flexupload.swf
  33. * @access private
  34. * @var String
  35. */
  36. var $_pathToSWF;
  37.  
  38. /**
  39. * maximal allowed filesize
  40. * @access private
  41. * @var integer
  42. */
  43. var $_maxFileSize;
  44.  
  45. /**
  46. * maximal allowed files
  47. * @access private
  48. * @var integer
  49. */
  50. var $_maxFiles;
  51.  
  52. /**
  53. * allowed file extensions
  54. * @access private
  55. * @var String
  56. */
  57. var $_fileExtensions;
  58.  
  59. /**
  60. * the locale
  61. * @access private
  62. * @var String
  63. */
  64. var $_locale;
  65.  
  66. /**
  67. * the width of the flash movie
  68. * @access private
  69. * @var integer
  70. */
  71. var $_width;
  72.  
  73. /**
  74. * the height of the flash movie
  75. * @access private
  76. * @var integer
  77. */
  78. var $_height;
  79.  
  80. /**
  81. * message to show when using SWFObject an Flash-Plugin is missing or wrong version
  82. * @access private
  83. * @var string
  84. */
  85. 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>';
  86.  
  87. /**
  88. * path to the SWFObject Script
  89. * @access private
  90. * @var string
  91. */
  92. var $_pathToSWFObject = 'js/';
  93.  
  94. /**
  95. * Constructor
  96. *
  97. * @param String $postURL see {@link setPostURL}
  98. * @param String $pathToSWF see {@link setPathToSWF}
  99. * @param String $width see {@link setWidth}
  100. * @param String $height see {@link setHeight}
  101. * @param String $maxFileSize see {@link setMaxFileSize}
  102. * @param String $maxFiles see {@link setMaxFiles}
  103. * @param String $fileExtensions see {@link setFileExtensions}
  104. * @param String $locale see {@link setLocale}
  105. */
  106. function FlexUpload($postURL, $pathToSWF='', $width=500, $height=300, $maxFileSize=2097152,
  107. $maxFiles=100, $fileExtensions='*.gif;*.jpg;*.jpeg;*.png', $locale='' ) {
  108. $this->_postURL = $postURL;
  109. $this->_pathToSWF = $pathToSWF;
  110. $this->_width = $width;
  111. $this->_height = $height;
  112. $this->_maxFileSize = $maxFileSize;
  113. $this->_maxFiles = $maxFiles;
  114. $this->_fileExtensions = $fileExtensions;
  115. $this->_locale = $locale;
  116. }
  117.  
  118. /**
  119. * set the postURL parameter
  120. *
  121. * the postURL have to be a full url incl. protocol
  122. * e.g. "http://localhost/upload.php"
  123. *
  124. * @param String $postURL
  125. */
  126. function setPostURL($postURL) {
  127. $this->_postURL = $postURL;
  128. }
  129.  
  130. /**
  131. * set the path to the SWF file
  132. *
  133. * Give an absolute or relative path to flexupload.swf or an empty string if flexupload.swf is in the same
  134. * directory like the php-file using this class.
  135. *
  136. * default is empty string
  137. *
  138. * @param String $path
  139. */
  140. function setPathToSWF($path) {
  141. $this->_pathToSWF = $path;
  142. }
  143.  
  144. /**
  145. * set the width of the application
  146. *
  147. * the applet automatically scales to this width
  148. *
  149. * default is 500
  150. *
  151. * @param integer $w
  152. */
  153. function setWidth($w) {
  154. $this->_width = $w;
  155. }
  156.  
  157. /**
  158. * set the height of the application
  159. *
  160. * the applet automatically scales to this height
  161. *
  162. * default is 300
  163. *
  164. * @param integer $h
  165. */
  166. function setHeight($h) {
  167. $this->_height = $h;
  168. }
  169.  
  170. /**
  171. * set the maximum filesize (in bytes) allowed to upload
  172. *
  173. * default is 2MB (2097152 bytes)
  174. *
  175. * @param integer $mfs
  176. */
  177. function setMaxFileSize($mfs) {
  178. $this->_maxFileSize = intval($mfs);
  179. }
  180.  
  181. /**
  182. * set the maximum of files to upload at once
  183. *
  184. * set this to -1 for no limit
  185. *
  186. * default is 100
  187. *
  188. * @param integer $mf
  189. */
  190. function setMaxFiles($mf) {
  191. $this->_maxFiles = intval($mf);
  192. }
  193.  
  194. /**
  195. * set the allowed file extensions separated by semicolons (;)
  196. *
  197. * set to empty string for all files
  198. *
  199. * default is "*.gif;*.jpg;*.jpeg;*.png"
  200. *
  201. * @param String $fe
  202. */
  203. function setFileExtensions($fe) {
  204. $this->_fileExtensions = $fe;
  205. }
  206.  
  207.  
  208. /**
  209. * set the language file for the application
  210. *
  211. * e.g "locale/de.xml" or "http://www.example.com/flexupload/locale/de.xml"
  212. * set en empty string to use the default locale (english)
  213. *
  214. * default is ""
  215. *
  216. * @param integer $l
  217. */
  218. function setLocale($l) {
  219. $this->_locale = $l;
  220. }
  221.  
  222.  
  223. /**
  224. * set the message to show when using SWFObject an flash plugin is not installed or wrong version
  225. *
  226. * default is "You may not have everything you need ..."
  227. *
  228. * @param string $msg
  229. */
  230. function setNoFlashMessage($msg)
  231. {
  232. $this->_noFlashMsg = $msg;
  233. }
  234.  
  235. /**
  236. * set the path to the SWFObject JavaScript script
  237. *
  238. * default is "js/"
  239. *
  240. * @param string $path
  241. */
  242. function setPathToSWFObject($path)
  243. {
  244. $this->_pathToSWFObject = $path;
  245. }
  246.  
  247. /**
  248. * get the HTML code for implementing flexupload
  249. *
  250. * see {@link printHTML}
  251. *
  252. * @param Boolean $useSWFObject Use the SWFObject script for output (recommended)
  253. * @param String $divId a unique id for the SWFObject <div>-Tag
  254. * @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!
  255. *
  256. * @return String $HTML the html code for the application
  257. */
  258. function getHTML($useSWFObject=true, $divId='flexupload', $includeSWFObject=true)
  259. {
  260. $params = '?postURL='.rawurlencode($this->_postURL);
  261. $params .= '&maxFileSize='.$this->_maxFileSize;
  262. $params .= '&maxFiles='.$this->_maxFiles;
  263. $params .= '&fileExtensions='.rawurlencode($this->_fileExtensions);
  264. $params .= '&locale='.rawurlencode($this->_locale);
  265.  
  266. $content = '';
  267.  
  268. if ($useSWFObject) {
  269. if ($includeSWFObject)
  270. $content .= '<script type="text/javascript" src="'.$this->_pathToSWFObject.'swfobject.js"></script>';
  271. $content .= '<div id="'.$divId.'">'.$this->_noFlashMsg."\n";
  272. $content .= '<script type="text/javascript">'."\n";
  273. $content .= '// <![CDATA['."\n";
  274. $content .= 'var obj_'.$divId.' = new SWFObject("'.$this->_pathToSWF.'flexupload.swf'.$params.'", "'.$divId.'", "'.$this->_width.'", "'.$this->_height.'", "9", "#869ca7");'."\n";
  275. $content .= 'obj_'.$divId.'.addParam("scale", "noscale");'."\n";
  276. $content .= 'obj_'.$divId.'.addParam("salign", "lt");'."\n";
  277. $content .= 'obj_'.$divId.'.addParam("menu", "false");'."\n";
  278. $content .= 'obj_'.$divId.'.addParam("quality", "best");'."\n";
  279. $content .= 'obj_'.$divId.'.addParam("wmode", "transparent");'."\n";
  280. $content .= 'obj_'.$divId.'.write("'.$divId.'");'."\n";
  281. $content .= '// ]]>'."\n";
  282. $content .= '</script>'."\n";
  283. } else {
  284. $content = '
  285. <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">
  286. <param name="movie" value="'.$this->_pathToSWF.'flexupload.swf'.$params.'" />
  287. <param name="quality" value="best" />
  288. <param name="bgcolor" value="#869ca7" />
  289. <param name="wmode" value="transparent" />
  290. <param name="menu" value="false" />
  291. <param name="scale" value="noscale" />
  292. <param name="salign" value="lt" />
  293. <embed src="'.$this->_pathToSWF.'flexupload.swf'.$params.'" quality="best" bgcolor="#869ca7"
  294. width="'.$this->_width.'" height="'.$this->_height.'" name="flexupload" align="middle" play="true" loop="false"
  295. wmode="transparent"
  296. menu="false"
  297. scale="noscale"
  298. salign="lt"
  299. type="application/x-shockwave-flash"
  300. pluginspage="http://www.adobe.com/go/getflashplayer">
  301. </embed>
  302. </object>';
  303. }
  304. return $content;
  305. }
  306.  
  307. /**
  308. * prints the HTML code for flexupload to screen
  309. *
  310. * see {@link getHTML}
  311. *
  312. * @param Boolean $useSWFObject Use the SWFObject script for output (recommended)
  313. * @param String $divId a unique id for the SWFObject <div>-Tag
  314. * @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!
  315. */
  316. function printHTML($useSWFObject=true, $divId='flexupload', $includeSWFObject=true) {
  317. echo $this->getHTML($useSWFObject, $divId, $includeSWFObject);
  318. }
  319. }
  320. ?>

Documentation generated on Sun, 17 Jun 2007 11:38:01 +0200 by phpDocumentor 1.3.0RC3