1--TEST-- 2Test file_put_contents() function : usage variation - obscure filenames 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if(substr(PHP_OS, 0, 3) != "WIN") 8 die("skip Only run on Windows"); 9?> 10--CONFLICTS-- 11obscure_filename 12--FILE-- 13<?php 14/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) 15 * Description: Write/Create a file with contents data and return the number of bytes written 16 * Source code: ext/standard/file.c 17 * Alias to functions: 18 */ 19 20echo "*** Testing file_put_contents() : usage variation ***\n"; 21 22/* An array of filenames */ 23$names_arr = array( 24 "-1" => -1, 25 "TRUE" => TRUE, 26 "FALSE" => FALSE, 27 "NULL" => NULL, 28 "\"\"" => "", 29 "\" \"" => " ", 30 "\\0" => "\0", 31 "array()" => array(), 32 33 /* prefix with path separator of a non existing directory*/ 34 "/no/such/file/dir" => "/no/such/file/dir", 35 "php/php"=> "php/php" 36 37); 38 39foreach($names_arr as $key =>$value) { 40 echo "\n-- Filename: $key --\n"; 41 $res = file_put_contents($value, "Some data"); 42 if ($res !== false && $res != null) { 43 echo "$res bytes written to: $value\n"; 44 unlink($value); 45 } else { 46 echo "Failed to write data to: $key\n"; 47 } 48}; 49 50?> 51===Done=== 52--EXPECTF-- 53*** Testing file_put_contents() : usage variation *** 54 55-- Filename: -1 -- 569 bytes written to: -1 57 58-- Filename: TRUE -- 599 bytes written to: 1 60 61-- Filename: FALSE -- 62 63Warning: file_put_contents(): Filename cannot be empty in %s on line %d 64Failed to write data to: FALSE 65 66-- Filename: NULL -- 67 68Warning: file_put_contents(): Filename cannot be empty in %s on line %d 69Failed to write data to: NULL 70 71-- Filename: "" -- 72 73Warning: file_put_contents(): Filename cannot be empty in %s on line %d 74Failed to write data to: "" 75 76-- Filename: " " -- 77 78Warning: file_put_contents( ): failed to open stream: Permission denied in %s on line %d 79Failed to write data to: " " 80 81-- Filename: \0 -- 82 83Warning: file_put_contents() expects parameter 1 to be a valid path, string given in %s on line %d 84Failed to write data to: \0 85 86-- Filename: array() -- 87 88Warning: file_put_contents() expects parameter 1 to be a valid path, array given in %s on line %d 89Failed to write data to: array() 90 91-- Filename: /no/such/file/dir -- 92 93Warning: file_put_contents(/no/such/file/dir): failed to open stream: %s in %s on line %d 94Failed to write data to: /no/such/file/dir 95 96-- Filename: php/php -- 97 98Warning: file_put_contents(php/php): failed to open stream: %s in %s on line %d 99Failed to write data to: php/php 100===Done=== 101