PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/strings/md5_file.php

http://github.com/facebook/hiphop-php
PHP | 71 lines | 34 code | 18 blank | 19 comment | 11 complexity | 4e434c7a2e24d118a370f3e596f919aa MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /* Prototype: string md5_file( string filename[, bool raw_output] )
  3. * Description: Calculate the MD5 hash of a given file
  4. */
  5. /* Creating an empty file */
  6. if (($handle = fopen( "EmptyFile.txt", "w+")) == FALSE)
  7. return false;
  8. /* Creating a data file */
  9. if (($handle2 = fopen( "DataFile.txt", "w+")) == FALSE)
  10. return false;
  11. /* Writing into file */
  12. $filename = "DataFile.txt";
  13. $content = "Add this to the file\n";
  14. if (is_writable($filename)) {
  15. if (fwrite($handle2, $content) === FALSE) {
  16. echo "Cannot write to file ($filename)";
  17. exit;
  18. }
  19. }
  20. // close the files
  21. fclose($handle);
  22. fclose($handle2);
  23. /* Testing error conditions */
  24. echo "\n*** Testing for error conditions ***\n";
  25. /* No filename */
  26. var_dump( md5_file("") );
  27. /* invalid filename */
  28. var_dump( md5_file("aZrq16u") );
  29. /* Scalar value as filename */
  30. var_dump( md5_file(12) );
  31. /* NULL as filename */
  32. var_dump( md5_file(NULL) );
  33. /* Zero arguments */
  34. var_dump ( md5_file() );
  35. /* More than valid number of arguments ( valid is 2) */
  36. var_dump ( md5_file("EmptyFile.txt", true, NULL) );
  37. /* Hexadecimal Output for Empty file as input */
  38. echo "\n*** Hexadecimal Output for Empty file as Argument ***\n";
  39. var_dump( md5_file("EmptyFile.txt") );
  40. /* Raw Binary Output for Empty file as input */
  41. echo "\n*** Raw Binary Output for Empty file as Argument ***\n";
  42. var_dump( md5_file("EmptyFile.txt", true) );
  43. /* Normal operation with hexadecimal output */
  44. echo "\n*** Hexadecimal Output for a valid file with some contents ***\n";
  45. var_dump( md5_file("DataFile.txt") );
  46. /* Normal operation with raw binary output */
  47. echo "\n*** Raw Binary Output for a valid file with some contents ***\n";
  48. var_dump ( md5_file("DataFile.txt", true) );
  49. // remove temp files
  50. unlink("DataFile.txt");
  51. unlink("EmptyFile.txt");
  52. echo "\nDone";
  53. ?>