/hphp/test/zend/good/ext/standard/tests/file/tempnam_variation1.php
PHP | 56 lines | 43 code | 9 blank | 4 comment | 10 complexity | 34dd375648680232c49f35505da2ba63 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
- <?hh
- /* Prototype: string tempnam ( string $dir, string $prefix );
- Description: Create file with unique file name.
- */
- /* Creating number of unique files by passing a file name as prefix */
- <<__EntryPoint>> function main(): void {
- $file_path = dirname(__FILE__)."/tempnamVar1";
- mkdir($file_path);
- echo "*** Testing tempnam() in creation of unique files ***\n";
- $files = darray[];
- for($i=1; $i<=10; $i++) {
- echo "-- Iteration $i --\n";
- $files[$i] = tempnam("$file_path", "tempnam_variation1.tmp");
- if( file_exists($files[$i]) ) {
- echo "File name is => ";
- print($files[$i]);
- echo "\n";
- echo "File permissions are => ";
- printf("%o", fileperms($files[$i]) );
- echo "\n";
- clearstatcache();
- echo "File inode is => ";
- print_r( fileinode($files[$i]) ); //checking inodes
- echo "\n";
- echo "File created in => ";
- $file_dir = dirname($files[$i]);
- if ($file_dir == sys_get_temp_dir()) {
- echo "temp dir\n";
- }
- else if ($file_dir == $file_path) {
- echo "directory specified\n";
- }
- else {
- echo "unknown location\n";
- }
- clearstatcache();
- }
- else {
- print("- File is not created -");
- }
- }
- for($i=1; $i<=10; $i++) {
- unlink($files[$i]);
- }
- rmdir($file_path);
- echo "*** Done ***\n";
- }