README.txt 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. sfwupload Module
  2. ================================================================================
  3. DESCRIPTION:
  4. --------------------------------------------------------------------------------
  5. The SWFUpload module provides an CCK widget for filefield and handles the upload
  6. through javascript/flash. It depends on the SWFUpload library which makes it
  7. possible to upload multiple file at once.
  8. For developers the module provides a hook function. Using this hook function
  9. developers can alter the way the widget is presented, op hook in to the file
  10. upload process.
  11. INSTALLATION:
  12. --------------------------------------------------------------------------------
  13. 1. Download the FileField module.
  14. (http://drupal.org/project/filefield)
  15. 2. Download the jQuery Plugin Handler (jQp) module. This module is required for
  16. loading the SWFUpload javascript library.
  17. (http://drupal.org/project/jqp)
  18. 3. Place both modules, as well as the SWFUpload module, in your module
  19. directory.
  20. (sites/all/modules)
  21. 4. If you do not have created a 'libraries' directory yet, create one.
  22. (sites/all/libraries)
  23. 5. Create a new directory called 'swfupload' inside the 'libraries' folder.
  24. (sites/all/libraries)
  25. 6. Download the SWFUpload 2.2.0.1 release.
  26. (http://code.google.com/p/swfupload/downloads/list)
  27. 7. Copy the files 'swfupload.swf' and 'swfupload.js' to the swfupload folder
  28. inside the libraries folder. The end result will read:
  29. sites/all/libraries/swfupload/swfupload.js
  30. sites/all/libraries/swfupload/swfupload.swf
  31. 8. Enable this module by navigating to:
  32. admin/build/modules
  33. 9. Ensure the library is available by visiting:
  34. admin/build/jqp/swfupload/
  35. USAGE:
  36. --------------------------------------------------------------------------------
  37. Create a new file field in through CCK's interface. Visit Administer -> Content
  38. management -> Content types (admin/content/types), then click Manage fields on
  39. the type you want to add an SWFUpload field. Select "File" as the field type and
  40. "SWFUpload" as the widget type to create a new field.
  41. On the field configuration screen set the "Permitted upload file extensions"
  42. to include the image types you will allow users to upload.
  43. Grant the permission to "upload files with swfupload" to the appropriate roles.
  44. API:
  45. --------------------------------------------------------------------------------
  46. Developers can take the advantage of the hook function hook_swfupload(). Using
  47. this function developers have access to alter the way the files are displayed,
  48. as well as how file uploads are processed.
  49. HOOK_SWFUPLOAD():
  50. DEFINITION:
  51. hook_swfupload(&$file, $op, &$instance, $widget)
  52. DESCRIPTION:
  53. Provide other modules a hook to change the data for the swfupload scripts.
  54. Modules can change the default provided fields, customize the way files are
  55. uploaded and change the type of swfupload (table or button).
  56. PARAMETERS:
  57. $file: The file object in its different states.
  58. $op: What kind of action is being performed. Possible values:
  59. 'init': The swfupload is being initialized. Here you can change the instance
  60. object in order to define other javascript callback functions, or to
  61. change the way the files are displayed.
  62. 'move_uploaded_file': The swfupload requests an upload. Here you can alter
  63. the file object in order to change it's filename or the destination
  64. folder. You can also change the validation functions which are passed
  65. to file_save_upload(). The file object will look something similar
  66. like this:
  67. $file = (object) array(
  68. 'validators' => array(
  69. 'file_validate_extensions => 'jpg jpeg gif png txt',
  70. 'filefield_validate_image_resolution' => array('800x600', '100x100'),
  71. 'file_validate_size' => array($widget->max_filesize_per_file, $widget->max_filesize_per_file),
  72. ),
  73. 'file_path' => 'files/'
  74. );
  75. 'upload_complete': The upload is complete. Using the hook_function in this
  76. state, the file can be copied, modified or you can do some database
  77. stuff. The file object will look something similar like this:
  78. $file = (object) array(
  79. 'filename' => 'Image1.png',
  80. 'filepath' => 'files/Image1_3.png',
  81. 'filemime' => 'image/png',
  82. 'source' => 'upload',
  83. 'destination' => 'files/Image1_3.png',
  84. 'filesize' => 220567,
  85. 'uid' => '3',
  86. 'status' => 0,
  87. 'timestamp' => 1227182505,
  88. 'fid' => '2468' }
  89. ),
  90. 'filepath' => 'files/'
  91. );
  92. $instance: The instance object in its different states. When $op is 'init' the
  93. instance can be altered in order to change the callback functions or to change
  94. the way the upload module displayes files. When $op is 'move_uploaded_file' or
  95. 'upload_complete', the instance object can be used as a reference.
  96. The reference object on init:
  97. // The type of the instance. Currently only table is supported
  98. $instance->type = 'table';
  99. // Javascript callback functions
  100. $instance->callbacks = array(
  101. 'swfupload_loaded_handler' => 'ref.swfUploadLoaded',
  102. 'file_queued_handler' => 'ref.fileQueued',
  103. 'queue_complete_handler' => 'ref.queueComplete',
  104. 'file_queue_error_handler' => 'ref.fileQueueError',
  105. 'file_dialog_complete_handler' => 'ref.dialogComplete',
  106. 'upload_success_handler' => 'ref.uploadSuccess',
  107. 'upload_progress_handler' => 'ref.uploadProgress',
  108. 'upload_error_handler' => 'ref.uploadError',
  109. 'upload_complete_handler' => 'ref.uploadComplete',
  110. 'init_complete_handler' => 'ref.initComplete',
  111. );
  112. // The $instance->elements array represents all elements (or columns) which are displayed on added files.
  113. // Each element can be changed. Javascript will render the proper markup.
  114. // By default the elements below are used for each added file, however by changing the widget settings, an 'alt', 'title', 'description' or 'display' column can be added.
  115. $instance->elements = array(
  116. 'drag' => array(
  117. 'class' => 'drag first indentation',
  118. 'type' => 'drag',
  119. 'colspan' => 3,
  120. 'title' => t('Filename'),
  121. 'add_separator' => TRUE,
  122. ),
  123. 'icon' => array(
  124. 'type' => 'icon',
  125. 'class' => 'icon',
  126. ),
  127. 'filename' => array(
  128. 'type' => 'markup',
  129. 'value' => '[filename]',
  130. 'class' => 'text title',
  131. ),
  132. );
  133. EXAMPLE:
  134. /**
  135. * Implements hook_swfupload().
  136. */
  137. function MODULENAME_swfupload(&$file, $op, &$instance, $widget) {
  138. switch ($op) {
  139. case 'init':
  140. // Add a custom callback function to be executed after the scripts have
  141. // been initialized.
  142. $instance->callbacks['init_complete_handler'] = 'myCustomCallbackFunction';
  143. // Add a custom editabe tabledrawer.
  144. $instance->elements['test'] => array(
  145. 'class' => 'my-class', // The class for the td.
  146. 'type' => 'text', // An editable textfield will be added. Values will be saved!
  147. 'colspan' => 2, // Colspan for this td
  148. 'title' => t('Description'), // This will be used in the th
  149. 'add_separator' => TRUE, // Whether or not to put a separator between the colums in the thead.
  150. 'contains_progressbar' = TRUE, // Whether or not the progressbar can be put here during upload.
  151. );
  152. break;
  153. case 'move_uploaded_file':
  154. global $user;
  155. $file->filepath = "files/$user->uid/"; // Files will be stored in an user folder
  156. break;
  157. case 'upload_complete':
  158. db_query("INSERT INTO {mymoduletable} (fid, filename) VALUES ('%s', '%s')", $file->fid, $file->filename);
  159. break;
  160. }
  161. }
  162. BUGS:
  163. --------------------------------------------------------------------------------
  164. 1. If the swfupload is loaded inside a collapsed fieldset, Firefox occasionally
  165. crashes when the fieldset expanded.
  166. 2. If you're getting 'IO Error #2038' errors, try pasting the following in your
  167. .htaccess file, or visit http://swfupload.org/forum/generaldiscussion/92.
  168. SecFilterEngine Off
  169. SecFilterScanPOST Off
  170. KUDOS:
  171. --------------------------------------------------------------------------------
  172. Special thanks to Nathan Haug (quicksketch) for writing ImageField and helping
  173. me out developing the SWFUpload module, and Morten Nielsen (minus) for
  174. sponsoring the module.