unlink_basic.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Testing unlink() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : bool unlink ( string $filename [, resource $context] );
  6. Description : Deletes filename
  7. */
  8. $file_path = dirname(__FILE__);
  9. echo "*** Testing unlink() on a file ***\n";
  10. $filename = "$file_path/unlink_basic.tmp"; // temp file name used here
  11. $fp = fopen($filename, "w"); // create file
  12. fwrite($fp, "Hello World");
  13. fclose($fp);
  14. // delete file
  15. var_dump( unlink($filename) );
  16. var_dump( file_exists($filename) ); // confirm file doesnt exist
  17. echo "\n*** Testing unlink() : checking second argument ***\n";
  18. // creating a context
  19. $context = stream_context_create();
  20. // temp file name used here
  21. $filename = "$file_path/unlink_basic.tmp";
  22. $fp = fopen($filename, "w"); // create file
  23. fclose($fp);
  24. // delete file
  25. var_dump( unlink($filename, $context) ); // using $context in second argument
  26. var_dump( file_exists($filename) ); // confirm file doesnt exist
  27. echo "Done\n";
  28. ?>
  29. --EXPECTF--
  30. *** Testing unlink() on a file ***
  31. bool(true)
  32. bool(false)
  33. *** Testing unlink() : checking second argument ***
  34. bool(true)
  35. bool(false)
  36. Done