1--TEST-- 2Test umask() function: usage variations - perms from 0000 to 0350 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip.. only on Linux'); 7} 8?> 9--FILE-- 10<?php 11$file_path = __DIR__; 12 13/* Check umask() on file/dir */ 14 15echo "*** Testing umask() on file and directory ***\n"; 16// temp filename used 17$filename = "$file_path/umask_variation1.tmp"; 18// temp dir used 19$dirname = "$file_path/umask_variation1"; 20 21for($mask = 0000; $mask <= 0350; $mask++) { 22 echo "-- Setting umask to "; 23 echo sprintf('%03o', $mask); 24 echo " --\n"; 25 // setting umask 26 umask($mask); 27 28 /* umasking file */ 29 // creating temp file 30 $fp = fopen($filename, "w"); 31 fclose($fp); 32 echo "File permission : "; 33 // check file permission 34 echo substr(sprintf('%o', fileperms($filename)), -3); 35 echo "\n"; 36 // chmod file to 0777 to enable deletion 37 chmod($filename, 0777); 38 // delete temp file created here 39 unlink($filename); 40 41 /* umasking directory */ 42 // create temp dir 43 mkdir($dirname); 44 echo "Directory permission : "; 45 // check $dirname permission 46 echo substr(sprintf('%o', fileperms($dirname)), -3); 47 echo "\n"; 48 // chmod 0777 to enable deletion 49 chmod($dirname, 0777); 50 // delete temp dir created 51 rmdir($dirname); 52} 53 54echo "Done\n"; 55?> 56--EXPECT-- 57*** Testing umask() on file and directory *** 58-- Setting umask to 000 -- 59File permission : 666 60Directory permission : 777 61-- Setting umask to 001 -- 62File permission : 666 63Directory permission : 776 64-- Setting umask to 002 -- 65File permission : 664 66Directory permission : 775 67-- Setting umask to 003 -- 68File permission : 664 69Directory permission : 774 70-- Setting umask to 004 -- 71File permission : 662 72Directory permission : 773 73-- Setting umask to 005 -- 74File permission : 662 75Directory permission : 772 76-- Setting umask to 006 -- 77File permission : 660 78Directory permission : 771 79-- Setting umask to 007 -- 80File permission : 660 81Directory permission : 770 82-- Setting umask to 010 -- 83File permission : 666 84Directory permission : 767 85-- Setting umask to 011 -- 86File permission : 666 87Directory permission : 766 88-- Setting umask to 012 -- 89File permission : 664 90Directory permission : 765 91-- Setting umask to 013 -- 92File permission : 664 93Directory permission : 764 94-- Setting umask to 014 -- 95File permission : 662 96Directory permission : 763 97-- Setting umask to 015 -- 98File permission : 662 99Directory permission : 762 100-- Setting umask to 016 -- 101File permission : 660 102Directory permission : 761 103-- Setting umask to 017 -- 104File permission : 660 105Directory permission : 760 106-- Setting umask to 020 -- 107File permission : 646 108Directory permission : 757 109-- Setting umask to 021 -- 110File permission : 646 111Directory permission : 756 112-- Setting umask to 022 -- 113File permission : 644 114Directory permission : 755 115-- Setting umask to 023 -- 116File permission : 644 117Directory permission : 754 118-- Setting umask to 024 -- 119File permission : 642 120Directory permission : 753 121-- Setting umask to 025 -- 122File permission : 642 123Directory permission : 752 124-- Setting umask to 026 -- 125File permission : 640 126Directory permission : 751 127-- Setting umask to 027 -- 128File permission : 640 129Directory permission : 750 130-- Setting umask to 030 -- 131File permission : 646 132Directory permission : 747 133-- Setting umask to 031 -- 134File permission : 646 135Directory permission : 746 136-- Setting umask to 032 -- 137File permission : 644 138Directory permission : 745 139-- Setting umask to 033 -- 140File permission : 644 141Directory permission : 744 142-- Setting umask to 034 -- 143File permission : 642 144Directory permission : 743 145-- Setting umask to 035 -- 146File permission : 642 147Directory permission : 742 148-- Setting umask to 036 -- 149File permission : 640 150Directory permission : 741 151-- Setting umask to 037 -- 152File permission : 640 153Directory permission : 740 154-- Setting umask to 040 -- 155File permission : 626 156Directory permission : 737 157-- Setting umask to 041 -- 158File permission : 626 159Directory permission : 736 160-- Setting umask to 042 -- 161File permission : 624 162Directory permission : 735 163-- Setting umask to 043 -- 164File permission : 624 165Directory permission : 734 166-- Setting umask to 044 -- 167File permission : 622 168Directory permission : 733 169-- Setting umask to 045 -- 170File permission : 622 171Directory permission : 732 172-- Setting umask to 046 -- 173File permission : 620 174Directory permission : 731 175-- Setting umask to 047 -- 176File permission : 620 177Directory permission : 730 178-- Setting umask to 050 -- 179File permission : 626 180Directory permission : 727 181-- Setting umask to 051 -- 182File permission : 626 183Directory permission : 726 184-- Setting umask to 052 -- 185File permission : 624 186Directory permission : 725 187-- Setting umask to 053 -- 188File permission : 624 189Directory permission : 724 190-- Setting umask to 054 -- 191File permission : 622 192Directory permission : 723 193-- Setting umask to 055 -- 194File permission : 622 195Directory permission : 722 196-- Setting umask to 056 -- 197File permission : 620 198Directory permission : 721 199-- Setting umask to 057 -- 200File permission : 620 201Directory permission : 720 202-- Setting umask to 060 -- 203File permission : 606 204Directory permission : 717 205-- Setting umask to 061 -- 206File permission : 606 207Directory permission : 716 208-- Setting umask to 062 -- 209File permission : 604 210Directory permission : 715 211-- Setting umask to 063 -- 212File permission : 604 213Directory permission : 714 214-- Setting umask to 064 -- 215File permission : 602 216Directory permission : 713 217-- Setting umask to 065 -- 218File permission : 602 219Directory permission : 712 220-- Setting umask to 066 -- 221File permission : 600 222Directory permission : 711 223-- Setting umask to 067 -- 224File permission : 600 225Directory permission : 710 226-- Setting umask to 070 -- 227File permission : 606 228Directory permission : 707 229-- Setting umask to 071 -- 230File permission : 606 231Directory permission : 706 232-- Setting umask to 072 -- 233File permission : 604 234Directory permission : 705 235-- Setting umask to 073 -- 236File permission : 604 237Directory permission : 704 238-- Setting umask to 074 -- 239File permission : 602 240Directory permission : 703 241-- Setting umask to 075 -- 242File permission : 602 243Directory permission : 702 244-- Setting umask to 076 -- 245File permission : 600 246Directory permission : 701 247-- Setting umask to 077 -- 248File permission : 600 249Directory permission : 700 250-- Setting umask to 100 -- 251File permission : 666 252Directory permission : 677 253-- Setting umask to 101 -- 254File permission : 666 255Directory permission : 676 256-- Setting umask to 102 -- 257File permission : 664 258Directory permission : 675 259-- Setting umask to 103 -- 260File permission : 664 261Directory permission : 674 262-- Setting umask to 104 -- 263File permission : 662 264Directory permission : 673 265-- Setting umask to 105 -- 266File permission : 662 267Directory permission : 672 268-- Setting umask to 106 -- 269File permission : 660 270Directory permission : 671 271-- Setting umask to 107 -- 272File permission : 660 273Directory permission : 670 274-- Setting umask to 110 -- 275File permission : 666 276Directory permission : 667 277-- Setting umask to 111 -- 278File permission : 666 279Directory permission : 666 280-- Setting umask to 112 -- 281File permission : 664 282Directory permission : 665 283-- Setting umask to 113 -- 284File permission : 664 285Directory permission : 664 286-- Setting umask to 114 -- 287File permission : 662 288Directory permission : 663 289-- Setting umask to 115 -- 290File permission : 662 291Directory permission : 662 292-- Setting umask to 116 -- 293File permission : 660 294Directory permission : 661 295-- Setting umask to 117 -- 296File permission : 660 297Directory permission : 660 298-- Setting umask to 120 -- 299File permission : 646 300Directory permission : 657 301-- Setting umask to 121 -- 302File permission : 646 303Directory permission : 656 304-- Setting umask to 122 -- 305File permission : 644 306Directory permission : 655 307-- Setting umask to 123 -- 308File permission : 644 309Directory permission : 654 310-- Setting umask to 124 -- 311File permission : 642 312Directory permission : 653 313-- Setting umask to 125 -- 314File permission : 642 315Directory permission : 652 316-- Setting umask to 126 -- 317File permission : 640 318Directory permission : 651 319-- Setting umask to 127 -- 320File permission : 640 321Directory permission : 650 322-- Setting umask to 130 -- 323File permission : 646 324Directory permission : 647 325-- Setting umask to 131 -- 326File permission : 646 327Directory permission : 646 328-- Setting umask to 132 -- 329File permission : 644 330Directory permission : 645 331-- Setting umask to 133 -- 332File permission : 644 333Directory permission : 644 334-- Setting umask to 134 -- 335File permission : 642 336Directory permission : 643 337-- Setting umask to 135 -- 338File permission : 642 339Directory permission : 642 340-- Setting umask to 136 -- 341File permission : 640 342Directory permission : 641 343-- Setting umask to 137 -- 344File permission : 640 345Directory permission : 640 346-- Setting umask to 140 -- 347File permission : 626 348Directory permission : 637 349-- Setting umask to 141 -- 350File permission : 626 351Directory permission : 636 352-- Setting umask to 142 -- 353File permission : 624 354Directory permission : 635 355-- Setting umask to 143 -- 356File permission : 624 357Directory permission : 634 358-- Setting umask to 144 -- 359File permission : 622 360Directory permission : 633 361-- Setting umask to 145 -- 362File permission : 622 363Directory permission : 632 364-- Setting umask to 146 -- 365File permission : 620 366Directory permission : 631 367-- Setting umask to 147 -- 368File permission : 620 369Directory permission : 630 370-- Setting umask to 150 -- 371File permission : 626 372Directory permission : 627 373-- Setting umask to 151 -- 374File permission : 626 375Directory permission : 626 376-- Setting umask to 152 -- 377File permission : 624 378Directory permission : 625 379-- Setting umask to 153 -- 380File permission : 624 381Directory permission : 624 382-- Setting umask to 154 -- 383File permission : 622 384Directory permission : 623 385-- Setting umask to 155 -- 386File permission : 622 387Directory permission : 622 388-- Setting umask to 156 -- 389File permission : 620 390Directory permission : 621 391-- Setting umask to 157 -- 392File permission : 620 393Directory permission : 620 394-- Setting umask to 160 -- 395File permission : 606 396Directory permission : 617 397-- Setting umask to 161 -- 398File permission : 606 399Directory permission : 616 400-- Setting umask to 162 -- 401File permission : 604 402Directory permission : 615 403-- Setting umask to 163 -- 404File permission : 604 405Directory permission : 614 406-- Setting umask to 164 -- 407File permission : 602 408Directory permission : 613 409-- Setting umask to 165 -- 410File permission : 602 411Directory permission : 612 412-- Setting umask to 166 -- 413File permission : 600 414Directory permission : 611 415-- Setting umask to 167 -- 416File permission : 600 417Directory permission : 610 418-- Setting umask to 170 -- 419File permission : 606 420Directory permission : 607 421-- Setting umask to 171 -- 422File permission : 606 423Directory permission : 606 424-- Setting umask to 172 -- 425File permission : 604 426Directory permission : 605 427-- Setting umask to 173 -- 428File permission : 604 429Directory permission : 604 430-- Setting umask to 174 -- 431File permission : 602 432Directory permission : 603 433-- Setting umask to 175 -- 434File permission : 602 435Directory permission : 602 436-- Setting umask to 176 -- 437File permission : 600 438Directory permission : 601 439-- Setting umask to 177 -- 440File permission : 600 441Directory permission : 600 442-- Setting umask to 200 -- 443File permission : 466 444Directory permission : 577 445-- Setting umask to 201 -- 446File permission : 466 447Directory permission : 576 448-- Setting umask to 202 -- 449File permission : 464 450Directory permission : 575 451-- Setting umask to 203 -- 452File permission : 464 453Directory permission : 574 454-- Setting umask to 204 -- 455File permission : 462 456Directory permission : 573 457-- Setting umask to 205 -- 458File permission : 462 459Directory permission : 572 460-- Setting umask to 206 -- 461File permission : 460 462Directory permission : 571 463-- Setting umask to 207 -- 464File permission : 460 465Directory permission : 570 466-- Setting umask to 210 -- 467File permission : 466 468Directory permission : 567 469-- Setting umask to 211 -- 470File permission : 466 471Directory permission : 566 472-- Setting umask to 212 -- 473File permission : 464 474Directory permission : 565 475-- Setting umask to 213 -- 476File permission : 464 477Directory permission : 564 478-- Setting umask to 214 -- 479File permission : 462 480Directory permission : 563 481-- Setting umask to 215 -- 482File permission : 462 483Directory permission : 562 484-- Setting umask to 216 -- 485File permission : 460 486Directory permission : 561 487-- Setting umask to 217 -- 488File permission : 460 489Directory permission : 560 490-- Setting umask to 220 -- 491File permission : 446 492Directory permission : 557 493-- Setting umask to 221 -- 494File permission : 446 495Directory permission : 556 496-- Setting umask to 222 -- 497File permission : 444 498Directory permission : 555 499-- Setting umask to 223 -- 500File permission : 444 501Directory permission : 554 502-- Setting umask to 224 -- 503File permission : 442 504Directory permission : 553 505-- Setting umask to 225 -- 506File permission : 442 507Directory permission : 552 508-- Setting umask to 226 -- 509File permission : 440 510Directory permission : 551 511-- Setting umask to 227 -- 512File permission : 440 513Directory permission : 550 514-- Setting umask to 230 -- 515File permission : 446 516Directory permission : 547 517-- Setting umask to 231 -- 518File permission : 446 519Directory permission : 546 520-- Setting umask to 232 -- 521File permission : 444 522Directory permission : 545 523-- Setting umask to 233 -- 524File permission : 444 525Directory permission : 544 526-- Setting umask to 234 -- 527File permission : 442 528Directory permission : 543 529-- Setting umask to 235 -- 530File permission : 442 531Directory permission : 542 532-- Setting umask to 236 -- 533File permission : 440 534Directory permission : 541 535-- Setting umask to 237 -- 536File permission : 440 537Directory permission : 540 538-- Setting umask to 240 -- 539File permission : 426 540Directory permission : 537 541-- Setting umask to 241 -- 542File permission : 426 543Directory permission : 536 544-- Setting umask to 242 -- 545File permission : 424 546Directory permission : 535 547-- Setting umask to 243 -- 548File permission : 424 549Directory permission : 534 550-- Setting umask to 244 -- 551File permission : 422 552Directory permission : 533 553-- Setting umask to 245 -- 554File permission : 422 555Directory permission : 532 556-- Setting umask to 246 -- 557File permission : 420 558Directory permission : 531 559-- Setting umask to 247 -- 560File permission : 420 561Directory permission : 530 562-- Setting umask to 250 -- 563File permission : 426 564Directory permission : 527 565-- Setting umask to 251 -- 566File permission : 426 567Directory permission : 526 568-- Setting umask to 252 -- 569File permission : 424 570Directory permission : 525 571-- Setting umask to 253 -- 572File permission : 424 573Directory permission : 524 574-- Setting umask to 254 -- 575File permission : 422 576Directory permission : 523 577-- Setting umask to 255 -- 578File permission : 422 579Directory permission : 522 580-- Setting umask to 256 -- 581File permission : 420 582Directory permission : 521 583-- Setting umask to 257 -- 584File permission : 420 585Directory permission : 520 586-- Setting umask to 260 -- 587File permission : 406 588Directory permission : 517 589-- Setting umask to 261 -- 590File permission : 406 591Directory permission : 516 592-- Setting umask to 262 -- 593File permission : 404 594Directory permission : 515 595-- Setting umask to 263 -- 596File permission : 404 597Directory permission : 514 598-- Setting umask to 264 -- 599File permission : 402 600Directory permission : 513 601-- Setting umask to 265 -- 602File permission : 402 603Directory permission : 512 604-- Setting umask to 266 -- 605File permission : 400 606Directory permission : 511 607-- Setting umask to 267 -- 608File permission : 400 609Directory permission : 510 610-- Setting umask to 270 -- 611File permission : 406 612Directory permission : 507 613-- Setting umask to 271 -- 614File permission : 406 615Directory permission : 506 616-- Setting umask to 272 -- 617File permission : 404 618Directory permission : 505 619-- Setting umask to 273 -- 620File permission : 404 621Directory permission : 504 622-- Setting umask to 274 -- 623File permission : 402 624Directory permission : 503 625-- Setting umask to 275 -- 626File permission : 402 627Directory permission : 502 628-- Setting umask to 276 -- 629File permission : 400 630Directory permission : 501 631-- Setting umask to 277 -- 632File permission : 400 633Directory permission : 500 634-- Setting umask to 300 -- 635File permission : 466 636Directory permission : 477 637-- Setting umask to 301 -- 638File permission : 466 639Directory permission : 476 640-- Setting umask to 302 -- 641File permission : 464 642Directory permission : 475 643-- Setting umask to 303 -- 644File permission : 464 645Directory permission : 474 646-- Setting umask to 304 -- 647File permission : 462 648Directory permission : 473 649-- Setting umask to 305 -- 650File permission : 462 651Directory permission : 472 652-- Setting umask to 306 -- 653File permission : 460 654Directory permission : 471 655-- Setting umask to 307 -- 656File permission : 460 657Directory permission : 470 658-- Setting umask to 310 -- 659File permission : 466 660Directory permission : 467 661-- Setting umask to 311 -- 662File permission : 466 663Directory permission : 466 664-- Setting umask to 312 -- 665File permission : 464 666Directory permission : 465 667-- Setting umask to 313 -- 668File permission : 464 669Directory permission : 464 670-- Setting umask to 314 -- 671File permission : 462 672Directory permission : 463 673-- Setting umask to 315 -- 674File permission : 462 675Directory permission : 462 676-- Setting umask to 316 -- 677File permission : 460 678Directory permission : 461 679-- Setting umask to 317 -- 680File permission : 460 681Directory permission : 460 682-- Setting umask to 320 -- 683File permission : 446 684Directory permission : 457 685-- Setting umask to 321 -- 686File permission : 446 687Directory permission : 456 688-- Setting umask to 322 -- 689File permission : 444 690Directory permission : 455 691-- Setting umask to 323 -- 692File permission : 444 693Directory permission : 454 694-- Setting umask to 324 -- 695File permission : 442 696Directory permission : 453 697-- Setting umask to 325 -- 698File permission : 442 699Directory permission : 452 700-- Setting umask to 326 -- 701File permission : 440 702Directory permission : 451 703-- Setting umask to 327 -- 704File permission : 440 705Directory permission : 450 706-- Setting umask to 330 -- 707File permission : 446 708Directory permission : 447 709-- Setting umask to 331 -- 710File permission : 446 711Directory permission : 446 712-- Setting umask to 332 -- 713File permission : 444 714Directory permission : 445 715-- Setting umask to 333 -- 716File permission : 444 717Directory permission : 444 718-- Setting umask to 334 -- 719File permission : 442 720Directory permission : 443 721-- Setting umask to 335 -- 722File permission : 442 723Directory permission : 442 724-- Setting umask to 336 -- 725File permission : 440 726Directory permission : 441 727-- Setting umask to 337 -- 728File permission : 440 729Directory permission : 440 730-- Setting umask to 340 -- 731File permission : 426 732Directory permission : 437 733-- Setting umask to 341 -- 734File permission : 426 735Directory permission : 436 736-- Setting umask to 342 -- 737File permission : 424 738Directory permission : 435 739-- Setting umask to 343 -- 740File permission : 424 741Directory permission : 434 742-- Setting umask to 344 -- 743File permission : 422 744Directory permission : 433 745-- Setting umask to 345 -- 746File permission : 422 747Directory permission : 432 748-- Setting umask to 346 -- 749File permission : 420 750Directory permission : 431 751-- Setting umask to 347 -- 752File permission : 420 753Directory permission : 430 754-- Setting umask to 350 -- 755File permission : 426 756Directory permission : 427 757Done 758