2
0

Zend_File_Transfer-Validators.xml 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.file.transfer.validators">
  4. <title>Validators for Zend_File_Transfer</title>
  5. <para>
  6. <classname>Zend_File_Transfer</classname> is delivered with several file-related validators
  7. which can be used to increase security and prevent possible attacks. Note that these
  8. validators are only as effective as how effectively you apply them. All validators provided
  9. with <classname>Zend_File_Transfer</classname> can be found in the
  10. <classname>Zend_Validator</classname> component and are named
  11. <classname>Zend_Validate_File_*</classname>. The following validators are available:
  12. </para>
  13. <itemizedlist>
  14. <listitem>
  15. <para>
  16. <classname>Count</classname>: This validator checks for the number of files. A
  17. minimum and maximum range can be specified. An error will be thrown if either limit
  18. is crossed.
  19. </para>
  20. </listitem>
  21. <listitem>
  22. <para>
  23. <classname>Crc32</classname>: This validator checks for the crc32 hash value of the
  24. content from a file. It is based on the <classname>Hash</classname> validator and
  25. provides a convenient and simple validator that only supports Crc32.
  26. </para>
  27. </listitem>
  28. <listitem>
  29. <para>
  30. <classname>ExcludeExtension</classname>: This validator checks the extension of
  31. files. It will throw an error when an given file has a defined extension. With this
  32. validator, you can exclude defined extensions from being validated.
  33. </para>
  34. </listitem>
  35. <listitem>
  36. <para>
  37. <classname>ExcludeMimeType</classname>: This validator validates the
  38. <acronym>MIME</acronym> type of files. It can also validate <acronym>MIME</acronym>
  39. types and will throw an error if the <acronym>MIME</acronym> type of specified file
  40. matches.
  41. </para>
  42. </listitem>
  43. <listitem>
  44. <para>
  45. <classname>Exists</classname>: This validator checks for the existence of files. It
  46. will throw an error when a specified file does not exist.
  47. </para>
  48. </listitem>
  49. <listitem>
  50. <para>
  51. <classname>Extension</classname>: This validator checks the extension of files. It
  52. will throw an error when a specified file has an undefined extension.
  53. </para>
  54. </listitem>
  55. <listitem>
  56. <para>
  57. <classname>FilesSize</classname>: This validator checks the size of validated files.
  58. It remembers internally the size of all checked files and throws an error when the
  59. sum of all specified files exceed the defined size. It also provides minimum and
  60. maximum values.
  61. </para>
  62. </listitem>
  63. <listitem>
  64. <para>
  65. <classname>ImageSize</classname>: This validator checks the size of image. It
  66. validates the width and height and enforces minimum and maximum dimensions.
  67. </para>
  68. </listitem>
  69. <listitem>
  70. <para>
  71. <classname>IsCompressed</classname>: This validator checks whether the file is
  72. compressed. It is based on the <classname>MimeType</classname> validator and
  73. validates for compression archives like zip or arc. You can also limit it to other
  74. archives.
  75. </para>
  76. </listitem>
  77. <listitem>
  78. <para>
  79. <classname>IsImage</classname>: This validator checks whether the file is an image.
  80. It is based on the <classname>MimeType</classname> validator and validates for image
  81. files like jpg or gif. You can also limit it to other image types.
  82. </para>
  83. </listitem>
  84. <listitem>
  85. <para>
  86. <classname>Hash</classname>: This validator checks the hash value of the content
  87. from a file. It supports multiple algorithms.
  88. </para>
  89. </listitem>
  90. <listitem>
  91. <para>
  92. <classname>Md5</classname>: This validator checks for the md5 hash value of the
  93. content from a file. It is based on the <classname>Hash</classname> validator and
  94. provides a convenient and simple validator that only supports Md5.
  95. </para>
  96. </listitem>
  97. <listitem>
  98. <para>
  99. <classname>MimeType</classname>: This validator validates the
  100. <acronym>MIME</acronym> type of files. It can also validate <acronym>MIME</acronym>
  101. types and will throw an error if the <acronym>MIME</acronym> type of a specified
  102. file does not match.
  103. </para>
  104. </listitem>
  105. <listitem>
  106. <para>
  107. <classname>NotExists</classname>: This validator checks for the existence of files.
  108. It will throw an error when an given file does exist.
  109. </para>
  110. </listitem>
  111. <listitem>
  112. <para>
  113. <classname>Sha1</classname>: This validator checks for the sha1 hash value of the
  114. content from a file. It is based on the <classname>Hash</classname> validator and
  115. provides a convenient and simple validator that only supports sha1.
  116. </para>
  117. </listitem>
  118. <listitem>
  119. <para>
  120. <classname>Size</classname>: This validator is able to check files for its file
  121. size. It provides a minimum and maximum size range and will throw an error when
  122. either of these thesholds are crossed.
  123. </para>
  124. </listitem>
  125. <listitem>
  126. <para>
  127. <classname>Upload</classname>: This validator is internal. It checks if an upload
  128. has resulted in an error. You must not set it, as it's automatically set by
  129. <classname>Zend_File_Transfer</classname> itself. So you do not use this validator
  130. directly. You should only know that it exists.
  131. </para>
  132. </listitem>
  133. <listitem>
  134. <para>
  135. <classname>WordCount</classname>: This validator is able to check the number of
  136. words within files. It provides a minimum and maximum count and will throw an error
  137. when either of these thresholds are crossed.
  138. </para>
  139. </listitem>
  140. </itemizedlist>
  141. <sect2 id="zend.file.transfer.validators.usage">
  142. <title>Using Validators with Zend_File_Transfer</title>
  143. <para>
  144. Putting validators to work is quite simple. There are several methods for adding and
  145. manipulating validators:
  146. </para>
  147. <itemizedlist>
  148. <listitem>
  149. <para>
  150. <methodname>isValid($files = null)</methodname>: Checks the specified files
  151. using all validators. <varname>$files</varname> may be either a real filename,
  152. the element's name or the name of the temporary file.
  153. </para>
  154. </listitem>
  155. <listitem>
  156. <para>
  157. <methodname>addValidator($validator, $breakChainOnFailure, $options = null,
  158. $files = null)</methodname>: Adds the specified validator to the validator
  159. stack (optionally only to the file(s) specified).
  160. <varname>$validator</varname> may be either an actual validator
  161. instance or a short name specifying the validator type (e.g., 'Count').
  162. </para>
  163. </listitem>
  164. <listitem>
  165. <para>
  166. <methodname>addValidators(array $validators, $files =
  167. null)</methodname>: Adds the specified validators to the stack of
  168. validators. Each entry may be either a validator
  169. type/options pair or an array with the key 'validator'
  170. specifying the validator. All other options will be
  171. considered validator options for instantiation.
  172. </para>
  173. </listitem>
  174. <listitem>
  175. <para>
  176. <methodname>setValidators(array $validators, $files =
  177. null)</methodname>: Overwrites any existing validators with
  178. the validators specified. The validators should follow the
  179. syntax for <methodname>addValidators()</methodname>.
  180. </para>
  181. </listitem>
  182. <listitem>
  183. <para>
  184. <methodname>hasValidator($name)</methodname>: Indicates whether a
  185. validator has been registered.
  186. </para>
  187. </listitem>
  188. <listitem>
  189. <para>
  190. <methodname>getValidator($name)</methodname>: Returns a previously
  191. registered validator.
  192. </para>
  193. </listitem>
  194. <listitem>
  195. <para>
  196. <methodname>getValidators($files = null)</methodname>: Returns
  197. registered validators. If <varname>$files</varname> is specified,
  198. returns validators for that particular file or set of
  199. files.
  200. </para>
  201. </listitem>
  202. <listitem>
  203. <para>
  204. <methodname>removeValidator($name)</methodname>: Removes a previously
  205. registered validator.
  206. </para>
  207. </listitem>
  208. <listitem>
  209. <para>
  210. <methodname>clearValidators()</methodname>: Clears all
  211. registered validators.
  212. </para>
  213. </listitem>
  214. </itemizedlist>
  215. <example id="zend.file.transfer.validators.usage.example">
  216. <title>Add Validators to a File Transfer Object</title>
  217. <programlisting language="php"><![CDATA[
  218. $upload = new Zend_File_Transfer();
  219. // Set a file size with 20000 bytes
  220. $upload->addValidator('Size', false, 20000);
  221. // Set a file size with 20 bytes minimum and 20000 bytes maximum
  222. $upload->addValidator('Size', false, array('min' => 20, 'max' => 20000));
  223. // Set a file size with 20 bytes minimum and 20000 bytes maximum and
  224. // a file count in one step
  225. $upload->setValidators(array(
  226. 'Size' => array('min' => 20, 'max' => 20000),
  227. 'Count' => array('min' => 1, 'max' => 3),
  228. ));
  229. ]]></programlisting>
  230. </example>
  231. <example id="zend.file.transfer.validators.usage.exampletwo">
  232. <title>Limit Validators to Single Files</title>
  233. <para>
  234. <methodname>addValidator()</methodname>, <methodname>addValidators()</methodname>,
  235. and <methodname>setValidators()</methodname> each accept a final
  236. <varname>$files</varname> argument. This argument can be used to
  237. specify a particular file or array of files on which to set the
  238. given validator.
  239. </para>
  240. <programlisting language="php"><![CDATA[
  241. $upload = new Zend_File_Transfer();
  242. // Set a file size with 20000 bytes and limits it only to 'file2'
  243. $upload->addValidator('Size', false, 20000, 'file2');
  244. ]]></programlisting>
  245. </example>
  246. <para>
  247. Normally, you should use the <methodname>addValidators()</methodname> method, which
  248. can be called multiple times.
  249. </para>
  250. <example id="zend.file.transfer.validators.usage.examplemultiple">
  251. <title>Add Multiple Validators</title>
  252. <para>
  253. Often it's simpler just to call <methodname>addValidator()</methodname> multiple
  254. times with one call for each validator. This also increases readability and makes
  255. your code more maintainable. All methods provide a fluent interface, so you can
  256. couple the calls as shown below:
  257. </para>
  258. <programlisting language="php"><![CDATA[
  259. $upload = new Zend_File_Transfer();
  260. // Set a file size with 20000 bytes
  261. $upload->addValidator('Size', false, 20000)
  262. ->addValidator('Count', false, 2)
  263. ->addValidator('Filessize', false, 25000);
  264. ]]></programlisting>
  265. </example>
  266. <note>
  267. <para>
  268. Note that setting the same validator
  269. multiple times is allowed, but doing so can lead to issues when using
  270. different options for the same validator.
  271. </para>
  272. </note>
  273. <para>
  274. Last but not least, you can simply check the files using
  275. <methodname>isValid()</methodname>.
  276. </para>
  277. <example id="zend.file.transfer.validators.usage.exampleisvalid">
  278. <title>Validate the Files</title>
  279. <para>
  280. <methodname>isValid()</methodname> accepts the file name of the uploaded or
  281. downloaded file, the temporary file name and or the name of the form element. If
  282. no parameter or null is given all files will be validated
  283. </para>
  284. <programlisting language="php"><![CDATA[
  285. $upload = new Zend_File_Transfer();
  286. // Set a file size with 20000 bytes
  287. $upload->addValidator('Size', false, 20000)
  288. ->addValidator('Count', false, 2)
  289. ->addValidator('Filessize', false, 25000);
  290. if (!$upload->isValid()) {
  291. print "Validation failure";
  292. }
  293. ]]></programlisting>
  294. </example>
  295. <note>
  296. <para>
  297. Note that <methodname>isValid()</methodname> will be called automatically when you
  298. receive the files and have not called it previously.
  299. </para>
  300. </note>
  301. <para>
  302. When validation has failed it is a good idea to get information about the
  303. problems found. To get this information, you can use the methods
  304. <methodname>getMessages()</methodname> which returns all validation messages as array,
  305. <methodname>getErrors()</methodname> which returns all error codes, and
  306. <methodname>hasErrors()</methodname> which returns <constant>TRUE</constant> as soon as
  307. a validation error has been found.
  308. </para>
  309. </sect2>
  310. <sect2 id="zend.file.transfer.validators.count">
  311. <title>Count Validator</title>
  312. <para>
  313. The <classname>Count</classname> validator checks for the number of files which are
  314. provided. It supports the following option keys:
  315. </para>
  316. <itemizedlist>
  317. <listitem>
  318. <para>
  319. <property>min</property>: Sets the minimum number of files to transfer.
  320. </para>
  321. <note>
  322. <para>
  323. When using this option you must give the minimum number of files when
  324. calling this validator the first time; otherwise you will get an error in
  325. return.
  326. </para>
  327. </note>
  328. <para>
  329. With this option you can define the minimum number of files you expect to
  330. receive.
  331. </para>
  332. </listitem>
  333. <listitem>
  334. <para>
  335. <property>max</property>: Sets the maximum number of files to transfer.
  336. </para>
  337. <para>
  338. With this option you can limit the number of files which are accepted but also
  339. detect a possible attack when more files are given than defined in your form.
  340. </para>
  341. </listitem>
  342. </itemizedlist>
  343. <para>
  344. If you initiate this validator with a string or integer, the value will be used as
  345. <property>max</property>. Or you can also use the methods
  346. <methodname>setMin()</methodname> and <methodname>setMax()</methodname> to set both
  347. options afterwards and <methodname>getMin()</methodname> and
  348. <methodname>getMax()</methodname> to retrieve the actual set values.
  349. </para>
  350. <example id="zend.file.transfer.validators.count.example">
  351. <title>Using the Count Validator</title>
  352. <programlisting language="php"><![CDATA[
  353. $upload = new Zend_File_Transfer();
  354. // Limit the amount of files to maximum 2
  355. $upload->addValidator('Count', false, 2);
  356. // Limit the amount of files to maximum 5 and minimum 1 file
  357. $upload->addValidator('Count', false, array('min' =>1, 'max' => 5));
  358. ]]></programlisting>
  359. </example>
  360. <note>
  361. <para>
  362. Note that this validator stores the number of checked files internally. The file
  363. which exceeds the maximum will be returned as error.
  364. </para>
  365. </note>
  366. </sect2>
  367. <sect2 id="zend.file.transfer.validators.crc32">
  368. <title>Crc32 Validator</title>
  369. <para>
  370. The <classname>Crc32</classname> validator checks the content of a transferred file by
  371. hashing it. This validator uses the hash extension from <acronym>PHP</acronym> with the
  372. crc32 algorithm. It supports the following options:
  373. </para>
  374. <itemizedlist>
  375. <listitem>
  376. <para>
  377. <property>*</property>: Sets any key or use a numeric array. The values will be
  378. used as hash to validate against.
  379. </para>
  380. <para>
  381. You can set multiple hashes by using different keys. Each will be checked and
  382. the validation will fail only if all values fail.
  383. </para>
  384. </listitem>
  385. </itemizedlist>
  386. <example id="zend.file.transfer.validators.crc32.example">
  387. <title>Using the Crc32 Validator</title>
  388. <programlisting language="php"><![CDATA[
  389. $upload = new Zend_File_Transfer();
  390. // Checks whether the content of the uploaded file has the given hash
  391. $upload->addValidator('Crc32', false, '3b3652f');
  392. // Limits this validator to two different hashes
  393. $upload->addValidator('Crc32', false, array('3b3652f', 'e612b69'));
  394. ]]></programlisting>
  395. </example>
  396. </sect2>
  397. <sect2 id="zend.file.transfer.validators.excludeextension">
  398. <title>ExcludeExtension Validator</title>
  399. <para>
  400. The <classname>ExcludeExtension</classname> validator checks the file extension of the
  401. specified files. It supports the following options:
  402. </para>
  403. <itemizedlist>
  404. <listitem>
  405. <para>
  406. <property>*</property>: Sets any key or use a numeric array. The values will be
  407. used to check whether the given file does not use this file extension.
  408. </para>
  409. </listitem>
  410. <listitem>
  411. <para>
  412. <property>case</property>: Sets a boolean indicating whether validation should
  413. be case-sensitive. The default is not case sensitive. Note that this key can be
  414. applied to for all available extensions.
  415. </para>
  416. </listitem>
  417. </itemizedlist>
  418. <para>
  419. This validator accepts multiple extensions, either as a comma-delimited string, or as
  420. an array. You may also use the methods <methodname>setExtension()</methodname>,
  421. <methodname>addExtension()</methodname>, and <methodname>getExtension()</methodname>
  422. to set and retrieve extensions.
  423. </para>
  424. <para>
  425. In some cases it is useful to match in a case-sensitive fashion. So the constructor
  426. allows a second parameter called <varname>$case</varname> which, if set to
  427. <constant>TRUE</constant>, validates the extension by comparing it with the specified
  428. values in a case-sensitive fashion.
  429. </para>
  430. <example id="zend.file.transfer.validators.excludeextension.example">
  431. <title>Using the ExcludeExtension Validator</title>
  432. <programlisting language="php"><![CDATA[
  433. $upload = new Zend_File_Transfer();
  434. // Do not allow files with extension php or exe
  435. $upload->addValidator('ExcludeExtension', false, 'php,exe');
  436. // Do not allow files with extension php or exe, but use array notation
  437. $upload->addValidator('ExcludeExtension', false, array('php', 'exe'));
  438. // Check in a case-sensitive fashion
  439. $upload->addValidator('ExcludeExtension',
  440. false,
  441. array('php', 'exe', 'case' => true));
  442. $upload->addValidator('ExcludeExtension',
  443. false,
  444. array('php', 'exe', 'case' => true));
  445. ]]></programlisting>
  446. </example>
  447. <note>
  448. <para>
  449. Note that this validator only checks the file extension. It does not check the
  450. file's <acronym>MIME</acronym> type.
  451. </para>
  452. </note>
  453. </sect2>
  454. <sect2 id="zend.file.transfer.validators.excludemimetype">
  455. <title>ExcludeMimeType Validator</title>
  456. <para>
  457. The <classname>ExcludeMimeType</classname> validator checks the <acronym>MIME</acronym>
  458. type of transferred files. It supports the following options:
  459. </para>
  460. <itemizedlist>
  461. <listitem>
  462. <para>
  463. <property>*</property>: Sets any key individually or use a numeric array. Sets
  464. the <acronym>MIME</acronym> type to validate against.
  465. </para>
  466. <para>
  467. With this option you can define the <acronym>MIME</acronym> type of files that
  468. are not to be accepted.
  469. </para>
  470. </listitem>
  471. <listitem>
  472. <para>
  473. <property>headerCheck</property>: If set to <constant>TRUE</constant> this
  474. option will check the <acronym>HTTP</acronym> Information for the file type when
  475. the <emphasis>fileInfo</emphasis> or <emphasis>mimeMagic</emphasis> extensions
  476. can not be found. The default value for this option is
  477. <constant>FALSE</constant>.
  478. </para>
  479. </listitem>
  480. </itemizedlist>
  481. <para>
  482. This validator accepts multiple <acronym>MIME</acronym> types, either as a
  483. comma-delimited string, or as an array. You may also use the methods
  484. <methodname>setMimeType()</methodname>, <methodname>addMimeType()</methodname>, and
  485. <methodname>getMimeType()</methodname> to set and retrieve the <acronym>MIME</acronym>
  486. types.
  487. </para>
  488. <example id="zend.file.transfer.validators.excludemimetype.example">
  489. <title>Using the ExcludeMimeType Validator</title>
  490. <programlisting language="php"><![CDATA[
  491. $upload = new Zend_File_Transfer();
  492. // Does not allow MIME type of gif images for all files
  493. $upload->addValidator('ExcludeMimeType', false, 'image/gif');
  494. // Does not allow MIME type of gif and jpg images for all given files
  495. $upload->addValidator('ExcludeMimeType', false, array('image/gif',
  496. 'image/jpeg');
  497. // Does not allow MIME type of the group images for all given files
  498. $upload->addValidator('ExcludeMimeType', false, 'image');
  499. ]]></programlisting>
  500. </example>
  501. <para>
  502. The above example shows that it is also possible to disallow groups of
  503. <acronym>MIME</acronym> types. For example, to disallow all images, just use 'image' as
  504. the <acronym>MIME</acronym> type. This can be used for all groups of
  505. <acronym>MIME</acronym> types like 'image', 'audio', 'video', 'text', etc.
  506. </para>
  507. <note>
  508. <para>
  509. Note that disallowing groups of <acronym>MIME</acronym> types will disallow all
  510. members of this group even if this is not intentional. When you disallow 'image' you
  511. will disallow all types of images like 'image/jpeg' or 'image/vasa'. When you are
  512. not sure if you want to disallow all types, you should disallow only specific
  513. <acronym>MIME</acronym> types instead of complete groups.
  514. </para>
  515. </note>
  516. </sect2>
  517. <sect2 id="zend.file.transfer.validators.exists">
  518. <title>Exists Validator</title>
  519. <para>
  520. The <classname>Exists</classname> validator checks for the existence of specified
  521. files. It supports the following options:
  522. </para>
  523. <itemizedlist>
  524. <listitem>
  525. <para>
  526. <property>*</property>: Sets any key or use a numeric array to check if the
  527. specific file exists in the given directory.
  528. </para>
  529. </listitem>
  530. </itemizedlist>
  531. <para>
  532. This validator accepts multiple directories, either as a comma-delimited string, or as
  533. an array. You may also use the methods <methodname>setDirectory()</methodname>,
  534. <methodname>addDirectory()</methodname>, and <methodname>getDirectory()</methodname>
  535. to set and retrieve directories.
  536. </para>
  537. <example id="zend.file.transfer.validators.exists.example">
  538. <title>Using the Exists Validator</title>
  539. <programlisting language="php"><![CDATA[
  540. $upload = new Zend_File_Transfer();
  541. // Add the temp directory to check for
  542. $upload->addValidator('Exists', false, '\temp');
  543. // Add two directories using the array notation
  544. $upload->addValidator('Exists',
  545. false,
  546. array('\home\images', '\home\uploads'));
  547. ]]></programlisting>
  548. </example>
  549. <note>
  550. <para>
  551. Note that this validator checks whether the specified file exists in all of the
  552. given directories. The validation will fail if the file does not exist in any of the
  553. given directories.
  554. </para>
  555. </note>
  556. </sect2>
  557. <sect2 id="zend.file.transfer.validators.extension">
  558. <title>Extension Validator</title>
  559. <para>
  560. The <classname>Extension</classname> validator checks the file extension of the
  561. specified files. It supports the following options:
  562. </para>
  563. <itemizedlist>
  564. <listitem>
  565. <para>
  566. <property>*</property>: Sets any key or use a numeric array to check whether the
  567. specified file has this file extension.
  568. </para>
  569. </listitem>
  570. <listitem>
  571. <para>
  572. <property>case</property>: Sets whether validation should be done in a
  573. case-sensitive fashion. The default is no case sensitivity. Note the this key is
  574. used for all given extensions.
  575. </para>
  576. </listitem>
  577. </itemizedlist>
  578. <para>
  579. This validator accepts multiple extensions, either as a comma-delimited string, or as an
  580. array. You may also use the methods <methodname>setExtension()</methodname>,
  581. <methodname>addExtension()</methodname>, and <methodname>getExtension()</methodname> to
  582. set and retrieve extension values.
  583. </para>
  584. <para>
  585. In some cases it is useful to test in a case-sensitive fashion. Therefore the
  586. constructor takes a second parameter <varname>$case</varname>, which, if set to
  587. <constant>TRUE</constant>, will validate the extension in a case-sensitive fashion.
  588. </para>
  589. <example id="zend.file.transfer.validators.extension.example">
  590. <title>Using the Extension Validator</title>
  591. <programlisting language="php"><![CDATA[
  592. $upload = new Zend_File_Transfer();
  593. // Limit the extensions to jpg and png files
  594. $upload->addValidator('Extension', false, 'jpg,png');
  595. // Limit the extensions to jpg and png files but use array notation
  596. $upload->addValidator('Extension', false, array('jpg', 'png'));
  597. // Check case sensitive
  598. $upload->addValidator('Extension', false, array('mo', 'png', 'case' => true));
  599. if (!$upload->isValid('C:\temp\myfile.MO')) {
  600. print 'Not valid because MO and mo do not match with case sensitivity;
  601. }
  602. ]]></programlisting>
  603. </example>
  604. <note>
  605. <para>
  606. Note that this validator only checks the file extension. It does not check the
  607. file's <acronym>MIME</acronym> type.
  608. </para>
  609. </note>
  610. </sect2>
  611. <sect2 id="zend.file.transfer.validators.filessize">
  612. <title>FilesSize Validator</title>
  613. <para>
  614. The <classname>FilesSize</classname> validator checks for the aggregate size of all
  615. transferred files. It supports the following options:
  616. </para>
  617. <itemizedlist>
  618. <listitem>
  619. <para>
  620. <property>min</property>: Sets the minimum aggregate file size.
  621. This option defines the minimum aggregate file size to be transferred.
  622. </para>
  623. </listitem>
  624. <listitem>
  625. <para>
  626. <property>max</property>: Sets the maximum aggregate file size.
  627. </para>
  628. <para>
  629. This option limits the aggregate file size of all transferred files, but not the
  630. file size of individual files.
  631. </para>
  632. </listitem>
  633. <listitem>
  634. <para>
  635. <property>bytestring</property>: Defines whether a failure is to return a
  636. user-friendly number or the plain file size.
  637. </para>
  638. <para>
  639. This option defines whether the user sees '10864' or '10MB'. The default value
  640. is <constant>TRUE</constant>, so '10MB' is returned if you did not specify
  641. otherwise.
  642. </para>
  643. </listitem>
  644. </itemizedlist>
  645. <para>
  646. You can initialize this validator with a string, which will then be used to set the
  647. <property>max</property> option. You can also use the methods
  648. <methodname>setMin()</methodname> and <methodname>setMax()</methodname> to set both
  649. options after construction, along with <methodname>getMin()</methodname> and
  650. <methodname>getMax()</methodname> to retrieve the values that have been set previously.
  651. </para>
  652. <para>
  653. The size itself is also accepted in SI notation as handled by most operating systems.
  654. That is, instead of specifying <emphasis>20000 bytes</emphasis>,
  655. <emphasis>20kB</emphasis> may be given. All file sizes are converted using 1024 as the
  656. base value. The following Units are accepted: <emphasis>kB</emphasis>,
  657. <emphasis>MB</emphasis>, <emphasis>GB</emphasis>, <emphasis>TB</emphasis>,
  658. <emphasis>PB</emphasis> and <emphasis>EB</emphasis>. Note that 1kB is equal to 1024
  659. bytes, 1MB is equal to 1024kB, and so on.
  660. </para>
  661. <example id="zend.file.transfer.validators.filessize.example">
  662. <title>Using the FilesSize Validator</title>
  663. <programlisting language="php"><![CDATA[
  664. $upload = new Zend_File_Transfer();
  665. // Limit the size of all files to be uploaded to 40000 bytes
  666. $upload->addValidator('FilesSize', false, 40000);
  667. // Limit the size of all files to be uploaded to maximum 4MB and mimimum 10kB
  668. $upload->addValidator('FilesSize',
  669. false,
  670. array('min' => '10kB', 'max' => '4MB'));
  671. // As before, but returns the plain file size instead of a user-friendly string
  672. $upload->addValidator('FilesSize',
  673. false,
  674. array('min' => '10kB',
  675. 'max' => '4MB',
  676. 'bytestring' => false));
  677. ]]></programlisting>
  678. </example>
  679. <note>
  680. <para>
  681. Note that this validator internally stores the file size of checked files. The file
  682. which exceeds the size will be returned as an error.
  683. </para>
  684. </note>
  685. </sect2>
  686. <sect2 id="zend.file.transfer.validators.imagesize">
  687. <title>ImageSize Validator</title>
  688. <para>
  689. The <classname>ImageSize</classname> validator checks the size of image files.
  690. It supports the following options:
  691. </para>
  692. <itemizedlist>
  693. <listitem>
  694. <para>
  695. <property>minheight</property>: Sets the minimum image height.
  696. </para>
  697. </listitem>
  698. <listitem>
  699. <para>
  700. <property>maxheight</property>: Sets the maximum image height.
  701. </para>
  702. </listitem>
  703. <listitem>
  704. <para>
  705. <property>minwidth</property>: Sets the minimum image width.
  706. </para>
  707. </listitem>
  708. <listitem>
  709. <para>
  710. <property>maxwidth</property>: Sets the maximum image width.
  711. </para>
  712. </listitem>
  713. </itemizedlist>
  714. <para>
  715. The methods <methodname>setImageMin()</methodname> and
  716. <methodname>setImageMax()</methodname> also set both minimum and maximum values, while
  717. the methods <methodname>getMin()</methodname> and <methodname>getMax()</methodname>
  718. return the currently set values.
  719. </para>
  720. <para>
  721. For your convenience there are also the <methodname>setImageWidth()</methodname> and
  722. <methodname>setImageHeight()</methodname> methods, which set the minimum and maximum
  723. height and width of the image file. They, too, have corresponding
  724. <methodname>getImageWidth()</methodname> and <methodname>getImageHeight()</methodname>
  725. methods to retrieve the currently set values.
  726. </para>
  727. <para>
  728. To bypass validation of a particular dimension, the relevent option simply should not be
  729. set.
  730. </para>
  731. <example id="zend.file.transfer.validators.imagesize.example">
  732. <title>Using the ImageSize Validator</title>
  733. <programlisting language="php"><![CDATA[
  734. $upload = new Zend_File_Transfer();
  735. // Limit the size of a image to a height of 100-200 and a width of
  736. // 40-80 pixel
  737. $upload->addValidator('ImageSize', false,
  738. array('minwidth' => 40,
  739. 'maxwidth' => 80,
  740. 'minheight' => 100,
  741. 'maxheight' => 200)
  742. );
  743. // Reset the width for validation
  744. $upload->setImageWidth(array('minwidth' => 20, 'maxwidth' => 200));
  745. ]]></programlisting>
  746. </example>
  747. </sect2>
  748. <sect2 id="zend.file.transfer.validators.iscompressed">
  749. <title>IsCompressed Validator</title>
  750. <para>
  751. The <classname>IsCompressed</classname> validator checks if a transferred file is a
  752. compressed archive, such as zip or arc. This validator is based on the
  753. <classname>MimeType</classname> validator and supports the same methods and options.
  754. You may also limit this validator to particular compression types with the methods
  755. described there.
  756. </para>
  757. <example id="zend.file.transfer.validators.iscompressed.example">
  758. <title>Using the IsCompressed Validator</title>
  759. <programlisting language="php"><![CDATA[
  760. $upload = new Zend_File_Transfer();
  761. // Checks is the uploaded file is a compressed archive
  762. $upload->addValidator('IsCompressed', false);
  763. // Limits this validator to zip files only
  764. $upload->addValidator('IsCompressed', false, array('application/zip'));
  765. // Limits this validator to zip files only using simpler notation
  766. $upload->addValidator('IsCompressed', false, 'zip');
  767. ]]></programlisting>
  768. </example>
  769. <note>
  770. <para>
  771. Note that there is no check if you set a <acronym>MIME</acronym> type that is not a
  772. archive. For example, it would be possible to define gif files to be accepted by
  773. this validator. Using the 'MimeType' validator for files which are not archived will
  774. result in more readable code.
  775. </para>
  776. </note>
  777. </sect2>
  778. <sect2 id="zend.file.transfer.validators.isimage">
  779. <title>IsImage Validator</title>
  780. <para>
  781. The <classname>IsImage</classname> validator checks if a transferred file is a image
  782. file, such as gif or jpeg. This validator is based on the
  783. <classname>MimeType</classname> validator and supports the same methods and options.
  784. You can limit this validator to particular image types with the methods described there.
  785. </para>
  786. <example id="zend.file.transfer.validators.isimage.example">
  787. <title>Using the IsImage Validator</title>
  788. <programlisting language="php"><![CDATA[
  789. $upload = new Zend_File_Transfer();
  790. // Checks whether the uploaded file is a image file
  791. $upload->addValidator('IsImage', false);
  792. // Limits this validator to gif files only
  793. $upload->addValidator('IsImage', false, array('application/gif'));
  794. // Limits this validator to jpeg files only using a simpler notation
  795. $upload->addValidator('IsImage', false, 'jpeg');
  796. ]]></programlisting>
  797. </example>
  798. <note>
  799. <para>
  800. Note that there is no check if you set a <acronym>MIME</acronym> type that is not an
  801. image. For example, it would be possible to define zip files to be accepted by this
  802. validator. Using the 'MimeType' validator for files which are not images will result
  803. in more readable code.
  804. </para>
  805. </note>
  806. </sect2>
  807. <sect2 id="zend.file.transfer.validators.hash">
  808. <title>Hash Validator</title>
  809. <para>
  810. The <classname>Hash</classname> validator checks the content of a transferred file by
  811. hashing it. This validator uses the hash extension from <acronym>PHP</acronym>. It
  812. supports the following options:
  813. </para>
  814. <itemizedlist>
  815. <listitem>
  816. <para>
  817. <property>*</property>: Takes any key or use a numeric array. Sets the hash to
  818. validate against.
  819. </para>
  820. <para>
  821. You can set multiple hashes by passing them as an array. Each file is checked,
  822. and the validation will fail only if all files fail validation.
  823. </para>
  824. </listitem>
  825. <listitem>
  826. <para>
  827. <property>algorithm</property>: Sets the algorithm to use for hashing the
  828. content.
  829. </para>
  830. <para>
  831. You can set multiple algorithm by calling the <methodname>addHash()</methodname>
  832. method multiple times.
  833. </para>
  834. </listitem>
  835. </itemizedlist>
  836. <example id="zend.file.transfer.validators.hash.example">
  837. <title>Using the Hash Validator</title>
  838. <programlisting language="php"><![CDATA[
  839. $upload = new Zend_File_Transfer();
  840. // Checks if the content of the uploaded file contains the given hash
  841. $upload->addValidator('Hash', false, '3b3652f');
  842. // Limits this validator to two different hashes
  843. $upload->addValidator('Hash', false, array('3b3652f', 'e612b69'));
  844. // Sets a different algorithm to check against
  845. $upload->addValidator('Hash',
  846. false,
  847. array('315b3cd8273d44912a7',
  848. 'algorithm' => 'md5'));
  849. ]]></programlisting>
  850. </example>
  851. <note>
  852. <para>
  853. This validator supports about 34 different hash algorithms. The most common include
  854. 'crc32', 'md5' and 'sha1'. A comprehesive list of supports hash algorithms can be
  855. found at the <ulink url="http://php.net/hash_algos">hash_algos method</ulink> on the
  856. <ulink url="http://php.net">php.net site</ulink>.
  857. </para>
  858. </note>
  859. </sect2>
  860. <sect2 id="zend.file.transfer.validators.md5">
  861. <title>Md5 Validator</title>
  862. <para>
  863. The <classname>Md5</classname> validator checks the content of a transferred file by
  864. hashing it. This validator uses the hash extension for <acronym>PHP</acronym> with the
  865. md5 algorithm. It supports the following options:
  866. </para>
  867. <itemizedlist>
  868. <listitem>
  869. <para>
  870. <property>*</property>: Takes any key or use a numeric array.
  871. </para>
  872. <para>
  873. You can set multiple hashes by passing them as an array. Each file is checked,
  874. and the validation will fail only if all files fail validation.
  875. </para>
  876. </listitem>
  877. </itemizedlist>
  878. <example id="zend.file.transfer.validators.md5.example">
  879. <title>Using the Md5 Validator</title>
  880. <programlisting language="php"><![CDATA[
  881. $upload = new Zend_File_Transfer();
  882. // Checks if the content of the uploaded file has the given hash
  883. $upload->addValidator('Md5', false, '3b3652f336522365223');
  884. // Limits this validator to two different hashes
  885. $upload->addValidator('Md5',
  886. false,
  887. array('3b3652f336522365223',
  888. 'eb3365f3365ddc65365'));
  889. ]]></programlisting>
  890. </example>
  891. </sect2>
  892. <sect2 id="zend.file.transfer.validators.mimetype">
  893. <title>MimeType Validator</title>
  894. <para>
  895. The <classname>MimeType</classname> validator checks the <acronym>MIME</acronym> type of
  896. transferred files. It supports the following options:
  897. </para>
  898. <itemizedlist>
  899. <listitem>
  900. <para>
  901. <property>*</property>: Sets any key or use a numeric array. Sets the
  902. <acronym>MIME</acronym> type to validate against.
  903. </para>
  904. <para>
  905. Defines the <acronym>MIME</acronym> type of files to be accepted.
  906. </para>
  907. </listitem>
  908. <listitem>
  909. <para>
  910. <property>headerCheck</property>: If set to <constant>TRUE</constant> this
  911. option will check the <acronym>HTTP</acronym> Information for the file type when
  912. the <emphasis>fileInfo</emphasis> or <emphasis>mimeMagic</emphasis> extensions
  913. can not be found. The default value for this option is
  914. <constant>FALSE</constant>.
  915. </para>
  916. </listitem>
  917. <listitem>
  918. <para>
  919. <property>magicfile</property>: The magicfile to be used.
  920. </para>
  921. <para>
  922. With this option you can define which magicfile to use. When it's not set or
  923. empty, the MAGIC constant will be used instead. This option is available since
  924. Zend Framework 1.7.1.
  925. </para>
  926. </listitem>
  927. </itemizedlist>
  928. <para>
  929. This validator accepts multiple <acronym>MIME</acronym> type, either as a
  930. comma-delimited string, or as an array. You may also use the methods
  931. <methodname>setMimeType()</methodname>, <methodname>addMimeType()</methodname>, and
  932. <methodname>getMimeType()</methodname> to set and retrieve <acronym>MIME</acronym>
  933. type.
  934. </para>
  935. <para>
  936. You can also set the magicfile which shall be used by fileinfo with the 'magicfile'
  937. option. Additionally there are convenient <methodname>setMagicFile()</methodname> and
  938. <methodname>getMagicFile()</methodname> methods which allow later setting and retrieving
  939. of the magicfile parameter. This methods are available since Zend Framework 1.7.1.
  940. </para>
  941. <example id="zend.file.transfer.validators.mimetype.example">
  942. <title>Using the MimeType Validator</title>
  943. <programlisting language="php"><![CDATA[
  944. $upload = new Zend_File_Transfer();
  945. // Limit the MIME type of all given files to gif images
  946. $upload->addValidator('MimeType', false, 'image/gif');
  947. // Limit the MIME type of all given files to gif and jpeg images
  948. $upload->addValidator('MimeType', false, array('image/gif', 'image/jpeg');
  949. // Limit the MIME type of all given files to the group images
  950. $upload->addValidator('MimeType', false, 'image');
  951. // Use a different magicfile
  952. $upload->addValidator('MimeType',
  953. false,
  954. array('image',
  955. 'magicfile' => '/path/to/magicfile.mgx'));
  956. ]]></programlisting>
  957. </example>
  958. <para>
  959. The above example shows that it is also possible to limit the accepted
  960. <acronym>MIME</acronym> type to a group of <acronym>MIME</acronym> types. To allow all
  961. images just use 'image' as <acronym>MIME</acronym> type. This can be used for all groups
  962. of <acronym>MIME</acronym> types like 'image', 'audio', 'video', 'text, and so on.
  963. </para>
  964. <note>
  965. <para>
  966. Note that allowing groups of <acronym>MIME</acronym> types will accept all members
  967. of this group even if your application does not support them. When you allow 'image'
  968. you will also get 'image/xpixmap' or 'image/vasa' which could be problematic. When
  969. you are not sure if your application supports all types you should better allow only
  970. defined <acronym>MIME</acronym> types instead of the complete group.
  971. </para>
  972. </note>
  973. <note>
  974. <para>
  975. This component will use the <classname>FileInfo</classname> extension if it is
  976. available. If it's not, it will degrade to the
  977. <methodname>mime_content_type()</methodname> function. And if the function call
  978. fails it will use the <acronym>MIME</acronym> type which is given by
  979. <acronym>HTTP</acronym>.
  980. </para>
  981. <para>
  982. You should be aware of possible security problems when you have whether
  983. <classname>FileInfo</classname> nor <methodname>mime_content_type()</methodname>
  984. available. The <acronym>MIME</acronym> type given by <acronym>HTTP</acronym> is not
  985. secure and can be easily manipulated.
  986. </para>
  987. </note>
  988. </sect2>
  989. <sect2 id="zend.file.transfer.validators.notexists">
  990. <title>NotExists Validator</title>
  991. <para>
  992. The <classname>NotExists</classname> validator checks for the existence of the provided
  993. files. It supports the following options:
  994. </para>
  995. <itemizedlist>
  996. <listitem>
  997. <para>
  998. <property>*</property>: Set any key or use a numeric array. Checks whether the
  999. file exists in the given directory.
  1000. </para>
  1001. </listitem>
  1002. </itemizedlist>
  1003. <para>
  1004. This validator accepts multiple directories either as a comma-delimited string, or as an
  1005. array. You may also use the methods <methodname>setDirectory()</methodname>,
  1006. <methodname>addDirectory()</methodname>, and <methodname>getDirectory()</methodname> to
  1007. set and retrieve directories.
  1008. </para>
  1009. <example id="zend.file.transfer.validators.notexists.example">
  1010. <title>Using the NotExists Validator</title>
  1011. <programlisting language="php"><![CDATA[
  1012. $upload = new Zend_File_Transfer();
  1013. // Add the temp directory to check
  1014. $upload->addValidator('NotExists', false, '\temp');
  1015. // Add two directories using the array notation
  1016. $upload->addValidator('NotExists', false,
  1017. array('\home\images',
  1018. '\home\uploads')
  1019. );
  1020. ]]></programlisting>
  1021. </example>
  1022. <note>
  1023. <para>
  1024. Note that this validator checks if the file does not exist in all of the provided
  1025. directories. The validation will fail if the file does exist in any of the given
  1026. directories.
  1027. </para>
  1028. </note>
  1029. </sect2>
  1030. <sect2 id="zend.file.transfer.validators.sha1">
  1031. <title>Sha1 Validator</title>
  1032. <para>
  1033. The <classname>Sha1</classname> validator checks the content of a transferred file by
  1034. hashing it. This validator uses the hash extension for <acronym>PHP</acronym> with the
  1035. sha1 algorithm. It supports the following options:
  1036. </para>
  1037. <itemizedlist>
  1038. <listitem>
  1039. <para>
  1040. <property>*</property>: Takes any key or use a numeric array.
  1041. </para>
  1042. <para>
  1043. You can set multiple hashes by passing them as an array. Each file is checked,
  1044. and the validation will fail only if all files fail validation.
  1045. </para>
  1046. </listitem>
  1047. </itemizedlist>
  1048. <example id="zend.file.transfer.validators.sha1.example">
  1049. <title>Using the sha1 Validator</title>
  1050. <programlisting language="php"><![CDATA[
  1051. $upload = new Zend_File_Transfer();
  1052. // Checks if the content of the uploaded file has the given hash
  1053. $upload->addValidator('sha1', false, '3b3652f336522365223');
  1054. // Limits this validator to two different hashes
  1055. $upload->addValidator('Sha1',
  1056. false, array('3b3652f336522365223',
  1057. 'eb3365f3365ddc65365'));
  1058. ]]></programlisting>
  1059. </example>
  1060. </sect2>
  1061. <sect2 id="zend.file.transfer.validators.size">
  1062. <title>Size Validator</title>
  1063. <para>
  1064. The <classname>Size</classname> validator checks for the size of a single file. It
  1065. supports the following options:
  1066. </para>
  1067. <itemizedlist>
  1068. <listitem>
  1069. <para>
  1070. <property>min</property>: Sets the minimum file size.
  1071. </para>
  1072. </listitem>
  1073. <listitem>
  1074. <para>
  1075. <property>max</property>: Sets the maximum file size.
  1076. </para>
  1077. </listitem>
  1078. <listitem>
  1079. <para>
  1080. <property>bytestring</property>: Defines whether a failure is returned with a
  1081. user-friendly number, or with the plain file size.
  1082. </para>
  1083. <para>
  1084. With this option you can define if the user gets '10864' or '10MB'. Default
  1085. value is <constant>TRUE</constant> which returns '10MB'.
  1086. </para>
  1087. </listitem>
  1088. </itemizedlist>
  1089. <para>
  1090. You can initialize this validator with a string, which will then be used to set the
  1091. <property>max</property> option. You can also use the methods
  1092. <methodname>setMin()</methodname> and <methodname>setMax()</methodname> to set both
  1093. options after construction, along with <methodname>getMin()</methodname> and
  1094. <methodname>getMax()</methodname> to retrieve the values that have been set previously.
  1095. </para>
  1096. <para>
  1097. The size itself is also accepted in SI notation as handled by most operating systems.
  1098. That is, instead of specifying <emphasis>20000 bytes</emphasis>,
  1099. <emphasis>20kB</emphasis> may be given. All file sizes are converted using 1024 as the
  1100. base value. The following Units are accepted: <emphasis>kB</emphasis>,
  1101. <emphasis>MB</emphasis>, <emphasis>GB</emphasis>, <emphasis>TB</emphasis>,
  1102. <emphasis>PB</emphasis> and <emphasis>EB</emphasis>. Note that 1kB is equal to 1024
  1103. bytes, 1MB is equal to 1024kB, and so on.
  1104. </para>
  1105. <example id="zend.file.transfer.validators.size.example">
  1106. <title>Using the Size Validator</title>
  1107. <programlisting language="php"><![CDATA[
  1108. $upload = new Zend_File_Transfer();
  1109. // Limit the size of a file to 40000 bytes
  1110. $upload->addValidator('Size', false, 40000);
  1111. // Limit the size a given file to maximum 4MB and mimimum 10kB
  1112. // Also returns the plain number in case of an error
  1113. // instead of a user-friendly number
  1114. $upload->addValidator('Size',
  1115. false,
  1116. array('min' => '10kB',
  1117. 'max' => '4MB',
  1118. 'bytestring' => false));
  1119. ]]></programlisting>
  1120. </example>
  1121. </sect2>
  1122. <sect2 id="zend.file.transfer.validators.wordcount">
  1123. <title>WordCount Validator</title>
  1124. <para>
  1125. The <classname>WordCount</classname> validator checks for the number of words within
  1126. provided files. It supports the following option keys:
  1127. </para>
  1128. <itemizedlist>
  1129. <listitem>
  1130. <para>
  1131. <property>min</property>: Sets the minimum number of words to be found.
  1132. </para>
  1133. </listitem>
  1134. <listitem>
  1135. <para>
  1136. <property>max</property>: Sets the maximum number of words to be found.
  1137. </para>
  1138. </listitem>
  1139. </itemizedlist>
  1140. <para>
  1141. If you initiate this validator with a string or integer, the value will be used as
  1142. <property>max</property>. Or you can also use the methods
  1143. <methodname>setMin()</methodname> and <methodname>setMax()</methodname> to set both
  1144. options afterwards and <methodname>getMin()</methodname> and
  1145. <methodname>getMax()</methodname> to retrieve the actual set values.
  1146. </para>
  1147. <example id="zend.file.transfer.validators.wordcount.example">
  1148. <title>Using the WordCount Validator</title>
  1149. <programlisting language="php"><![CDATA[
  1150. $upload = new Zend_File_Transfer();
  1151. // Limit the amount of words within files to maximum 2000
  1152. $upload->addValidator('WordCount', false, 2000);
  1153. // Limit the amount of words within files to maximum 5000 and minimum 1000 words
  1154. $upload->addValidator('WordCount', false, array('min' => 1000, 'max' => 5000));
  1155. ]]></programlisting>
  1156. </example>
  1157. </sect2>
  1158. </sect1>
  1159. <!--
  1160. vim:se ts=4 sw=4 tw=80 et:
  1161. -->