示例#1
1
<?php

// include the file.inc for Function: function create_files()
require dirname(__FILE__) . '/file.inc';
$path = dirname(__FILE__) . '/fseek_dir_basic';
mkdir($path);
create_files($path, 3);
echo "call readdir():\n";
var_dump($dh = opendir($path));
$files = array();
while (FALSE !== ($files[] = readdir($dh))) {
}
sort($files);
var_dump($files);
$files = array();
echo "\ncall fseek() on directory resource:\n";
var_dump(fseek($dh, 20));
echo "call readdir():\n";
while (FALSE !== ($files[] = readdir($dh))) {
}
sort($files);
var_dump($files);
$files = array();
echo "\ncall fseek() with different arguments on directory resource:\n";
var_dump(fseek($dh, 20, SEEK_END));
echo "call readdir():\n";
while (FALSE !== ($files[] = readdir($dh))) {
}
sort($files);
var_dump($files);
delete_files($path, 3);
示例#2
1
<?php

/* 
 * Prototype: array file ( string filename [,int use-include_path [,resource context]] );
 * Description: Reads entire file into an array
 *              Returns the  file in an array
 */
require dirname(__FILE__) . '/file.inc';
$file_path = dirname(__FILE__);
echo "*** Testing file() with basic types of files ***\n";
$filetypes = array("numeric", "text", "empty", "text_with_new_line");
foreach ($filetypes as $type) {
    create_files($file_path, 1, $type, 0755, 100, "w", "file_basic", 1, "byte");
    print_r(file($file_path . "/file_basic1.tmp"));
    delete_files($file_path, 1, "file_basic");
}
echo "*** Testing for return type of file() function ***\n";
foreach ($filetypes as $type) {
    create_files($file_path, 1, $type, 0755, 1, "w", "file_basic");
    $ret_arr = file($file_path . "/file_basic1.tmp");
    var_dump(is_array($ret_arr));
    delete_files($file_path, 1, "file_basic");
}
echo "\n--- Done ---";
<?php

/*
 Prototype: string fgetc ( resource $handle );
 Description: Gets character from file pointer
*/
// include the header for common test function
include "file.inc";
echo "*** Testing fgetc() : usage variations ***\n";
echo "-- Testing fgetc() with file whose file pointer is pointing to EOF --\n";
// create a file
create_files(dirname(__FILE__), 1, "text_with_new_line", 0755, 1, "w", "fgetc_variation");
$filename = dirname(__FILE__) . "/fgetc_variation1.tmp";
// loop to check the file opened in different read modes
$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t");
$loop_counter = 0;
for (; $loop_counter < count($file_modes); $loop_counter++) {
    // print the hearder
    echo "-- File opened in mode : {$file_modes[$loop_counter]} --\n";
    // open the file
    $file_handle = fopen($filename, $file_modes[$loop_counter]);
    if (!$file_handle) {
        echo "Error: failed to open file {$filename}! \n";
        exit;
    }
    // seek to end of the file and try fgetc()
    var_dump(fseek($file_handle, 0, SEEK_END));
    // set file pointer to eof
    var_dump(feof($file_handle));
    // expected false
    var_dump(ftell($file_handle));
示例#4
1
$base_tmp = "{$base_dir}/.tmp";
$base_db_ini = ".conn.ini";
$config_templete = ';本系統登入密碼
PASSWORD="******"
;資料庫設定
DB_HOST="localhost"
DB_LOGIN="******"
DB_PASSWORD=""
DB_NAME=""
;mysql mssql pgsql oracle
DB_KIND="mysql"
';
if (!is_dir($base_tmp)) {
    @mkdir($base_tmp, 0777);
}
create_files();
if (!is_file($base_db_ini)) {
    @touch($base_db_ini);
    file_put_contents($base_db_ini, $config_templete);
}
$ini_settings = parse_ini_file($base_db_ini);
check_login(false);
//load DB
$pdo = null;
try {
    $pdo = new PDO("{$ini_settings['DB_KIND']}:dbname={$ini_settings['DB_NAME']};host={$ini_settings['DB_HOST']}", $ini_settings['DB_LOGIN'], $ini_settings['DB_PASSWORD']);
    switch (strtoupper($ini_settings['DB_KIND'])) {
        case 'MSSQL':
            break;
        case 'ORACLE':
            break;
示例#5
1
                            [, bool $use_include_path [, resource $context]] );
 Description: Opens file or URL.
*/
/*
 fclose() function:
 Prototype: bool fclose ( resource $handle );
 Description: Closes an open file pointer
*/
/* Test fopen() and fclose(): Opening the file in "at" mode,
   checking for the file creation, write & read operations,
   checking for the file pointer position,
   and fclose function
*/
$file_path = dirname(__FILE__);
require $file_path . "/file.inc";
create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 13, "bytes");
$file = $file_path . "/007_variation13.tmp";
$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
echo "*** Test fopen() & fclose() functions:  with 'at' mode ***\n";
$file_handle = fopen($file, "at");
//opening the file "at" mode
var_dump($file_handle);
//Check for the content of handle
var_dump(get_resource_type($file_handle));
//Check for the type of resource
var_dump(fwrite($file_handle, $string));
//Check for write operation; passes; expected:size of the $string
rewind($file_handle);
var_dump(fread($file_handle, 100));
//Check for read operation; fails; expected: empty string
var_dump(ftell($file_handle));
示例#6
1
<?php

/* 
 Prototype   : int filesize ( string $filename );
 Description : Returns the size of the file in bytes, or FALSE 
   (and generates an error of level E_WARNING) in case of an error.
*/
$file_path = dirname(__FILE__);
require $file_path . "/file.inc";
echo "*** Testing filesize(): usage variations ***\n";
echo "*** Checking filesize() with different size of files ***\n";
for ($size = 1; $size < 10000; $size = $size + 1000) {
    create_files($file_path, 1, "numeric", 0755, $size, "w", "filesize_variation");
    var_dump(filesize($file_path . "/filesize_variation1.tmp"));
    clearstatcache();
    delete_files($file_path, 1, "filesize_variation");
}
echo "Done\n";
示例#7
1
include "file.inc";
/*
 Test fwrite with file opened in mode : a,ab,at,a+,a+b,a+
 File having content of type numeric, text,text_with_new_line & alphanumeric
*/
$file_modes = array("a", "ab", "at", "a+", "a+b", "a+t");
$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
foreach ($file_content_types as $file_content_type) {
    echo "\n-- Testing fwrite() with file having content of type " . $file_content_type . " --\n";
    /* open the file using $files_modes and perform fwrite() on it */
    foreach ($file_modes as $file_mode) {
        echo "-- Opening file in {$file_mode} --\n";
        // create temp file and fill it content of type $file_content_type
        $filename = dirname(__FILE__) . "/fwrite_variation3.tmp";
        // this is name of the file
        create_files(dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "fwrite_variation", 3);
        $file_handle = fopen($filename, $file_mode);
        if (!$file_handle) {
            echo "Error: failed to fopen() file: {$filename}!";
            exit;
        }
        $data_to_be_written = "";
        fill_buffer($data_to_be_written, $file_content_type, 1024);
        //get the data of size 1024
        /*  Write the data into the file, verify it by checking the file pointer position, eof position, 
            filesize & by displaying the content */
        // append the data to the file, starting from current position of the file pointer
        var_dump(ftell($file_handle));
        // expected: 1024
        var_dump(fwrite($file_handle, $data_to_be_written, 400));
        var_dump(ftell($file_handle));
 *  Prototype: int pclose ( resource handle );
 *  Description: Closes process file pointer.
 */
$file_path = dirname(__FILE__);
require $file_path . "/file.inc";
echo "*** Testing popen() and pclose() with different processes ***\n";
echo "-- Testing popen(): reading from the pipe --\n";
$dirpath = $file_path . "/popen_basic";
mkdir($dirpath);
touch($dirpath . "/popen_basic.tmp");
define('CMD', "ls {$dirpath}");
$file_handle = popen(CMD, 'r');
fpassthru($file_handle);
pclose($file_handle);
echo "-- Testing popen(): reading from a file using 'cat' command --\n";
create_files($dirpath, 1, "text_with_new_line", 0755, 100, "w", "popen_basic", 1, "bytes");
$filename = $dirpath . "/popen_basic1.tmp";
$command = "cat {$filename}";
$file_handle = popen($command, "r");
$return_value = fpassthru($file_handle);
echo "\n";
var_dump($return_value);
pclose($file_handle);
delete_files($dirpath, 1);
echo "*** Testing popen(): writing to the pipe ***\n";
$arr = array("ggg", "ddd", "aaa", "sss");
$file_handle = popen("sort", "w");
$counter = 0;
$newline = "\n";
foreach ($arr as $str) {
    fwrite($file_handle, (string) $str);
示例#9
0
<?php

/* Prototype: string file_get_contents( string $filename{, bool $use_include_path[,
 *                                      resource $context[, int $offset[, int $maxlen]]]] ) 
 * Description: Reads entire file into a string
 */
echo "*** Testing error conditions ***\n";
$file_path = dirname(__FILE__);
include $file_path . "/file.inc";
echo "\n-- Testing with  Non-existing file --\n";
print file_get_contents("/no/such/file/or/dir");
echo "\n-- Testing No.of arguments less than expected --\n";
print file_get_contents();
echo "\n-- Testing No.of arguments greater than expected --\n";
create_files($file_path, 1, "text", 0755, 100, "w", "file", 1, "byte");
$file_handle = fopen($file_path . "/file_put_contents_error.tmp", "w");
print file_get_contents($file_path . "/file1.tmp", false, $file_handle, 1, 2, "extra_argument");
echo "\n-- Testing for invalid negative maxlen values --";
var_dump(file_get_contents($file_path . "/file1.tmp", FALSE, $file_handle, 0, -5));
delete_files($file_path, 1);
fclose($file_handle);
unlink($file_path . "/file_put_contents_error.tmp");
echo "\n*** Done ***\n";
error_reporting(0);
$file_path = dirname(__FILE__);
if (file_exists($file_path . "/file_put_contents_error.tmp")) {
    unlink($file_path . "/file_put_contents_error.tmp");
}
if (file_exists($file_path . "/file_put_contents1.tmp")) {
    unlink($file_path . "/file_put_contents1.tmp");
}
示例#10
0
/*
 Prototype: string fgets ( resource $handle [, int $length] );
 Description: Gets a line from file pointer
*/
// include the file.inc for common test funcitons
include "file.inc";
$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t");
$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
echo "*** Testing fgets() : basic functionality ***\n";
foreach ($file_modes as $file_mode) {
    echo "\n-- Testing fgets() with file opened using mode {$file_mode} --\n";
    foreach ($file_content_types as $file_content_type) {
        echo "-- File content type : {$file_content_type} --\n";
        /* create files with $file_content_type */
        create_files(dirname(__FILE__), 1, $file_content_type, 0755, 50, "w", "fgets_basic", 1, "bytes");
        //create a file
        $filename = dirname(__FILE__) . "/fgets_basic1.tmp";
        // this is name of the file created by create_files()
        $file_handle = fopen($filename, $file_mode);
        if (!$file_handle) {
            echo "Error: failed to open file {$filename}!";
            exit;
        }
        echo "-- fgets() with default length, file pointer at 0 --\n";
        var_dump(fgets($file_handle));
        // with default length
        var_dump(ftell($file_handle));
        // ensure the file pointer position
        var_dump(feof($file_handle));
        // enusre if eof set
<?php

/* Prototype  : array scandir(string $dir [, int $sorting_order [, resource $context]])
 * Description: List files & directories inside the specified path 
 * Source code: ext/standard/dir.c
 */
/*
 * Test basic functionality of scandir()
 */
echo "*** Testing scandir() : basic functionality ***\n";
// include file.inc for create_files function
include dirname(__FILE__) . '/../file/file.inc';
// set up directory
$directory = dirname(__FILE__) . '/scandir_basic';
mkdir($directory);
create_files($directory, 3);
echo "\n-- scandir() with mandatory arguments --\n";
var_dump(scandir($directory));
echo "\n-- scandir() with all arguments --\n";
$sorting_order = SCANDIR_SORT_DESCENDING;
$context = stream_context_create();
var_dump(scandir($directory, $sorting_order, $context));
delete_files($directory, 3);
?>
===DONE===
示例#12
0
 * Description: Rewind dir_handle back to the start 
 * Source code: ext/standard/dir.c
 * Alias to functions: rewind
 */
/*
 * Test basic functionality of rewinddir()
 */
echo "*** Testing rewinddir() : basic functionality ***\n";
// include file.inc for create_files function
include dirname(__FILE__) . "/../file/file.inc";
$dir_path1 = dirname(__FILE__) . "/rewinddir_basic_dir1";
$dir_path2 = dirname(__FILE__) . "/rewinddir_basic_dir2";
mkdir($dir_path1);
mkdir($dir_path2);
@create_files($dir_path1, 1);
@create_files($dir_path2, 1, 'numeric', 0755, 1, 'w', 'file', 2);
var_dump($dh1 = opendir($dir_path1));
var_dump($dh2 = opendir($dir_path2));
$data = array();
echo "\n-- Read and rewind first directory (argument supplied) --\n";
while (FALSE !== ($file1 = readdir($dh1))) {
    $data[] = $file1;
}
$first = $data[0];
sort($data);
var_dump($data);
var_dump(rewinddir($dh1));
var_dump(readdir($dh1) == $first);
$data = array();
echo "\n-- Read and rewind second directory (no argument supplied) --\n";
while (FALSE !== ($file2 = readdir())) {
示例#13
0
<?php

/* 
 * Prototype  : object dir(string $directory[, resource $context])
 * Description: Directory class with properties, handle and class and methods read, rewind and close
 * Source code: ext/standard/dir.c
 */
echo "*** Testing dir() : basic functionality ***\n";
// include the file.inc for Function: function create_files()
include dirname(__FILE__) . "/../file/file.inc";
// create the temporary directory
$file_path = dirname(__FILE__);
$dir_path = $file_path . "/dir_basic";
@mkdir($dir_path);
// create files within the temporary directory
create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "dir_basic");
echo "Get Directory instance:\n";
$d = dir($dir_path);
var_dump($d);
echo "\nRead and rewind:\n";
var_dump($d->read());
var_dump($d->read());
var_dump($d->rewind());
echo "\nTest using handle directly:\n";
var_dump(readdir($d->handle));
var_dump(readdir($d->handle));
echo "\nClose directory:\n";
var_dump($d->close());
var_dump($d);
echo "\nTest read after closing the dir:";
var_dump($d->read());
示例#14
0
// common file used
require dirname(__FILE__) . '/file.inc';
echo "*** Testing readfile() : basic functionality ***\n";
$file_path = dirname(__FILE__);
$file_prefix = "readfile_basic";
// temp files created with this prefix
// the content that is filled into the temp files as created
$filetypes = array("numeric", "text", "empty", "alphanumeric", "text_with_new_line");
// different file modes
$filemodes = array("w", "wt", "wb", "w+", "w+b", "w+t", "a", "at", "ab", "a+", "a+b", "a+t", "x", "xb", "xt", "x+", "x+b", "x+t");
// create file, read the file content, delete file
foreach ($filetypes as $type) {
    echo "\n-- File filled with content type: {$type} --\n";
    foreach ($filemodes as $mode) {
        echo "-- File opened with mode: {$mode} --\n";
        if (strstr($mode, "x")) {
            $fp = fopen($file_path . "/" . $file_prefix . "1.tmp", $mode);
            fill_file($fp, $type, 100);
            fclose($fp);
        } else {
            // creating file in write mode
            create_files($file_path, 1, $type, 0755, 100, $mode, $file_prefix, 1, "byte");
        }
        $count = readfile($file_path . "/" . $file_prefix . "1.tmp");
        echo "\n";
        var_dump($count);
        // delete files created
        delete_files($file_path, 1, $file_prefix, 1);
    }
}
echo "Done\n";
示例#15
0
 Prototype: string fgetc ( resource $handle );
 Description: Gets character from file pointer
*/
// include the header for common test function
include "file.inc";
echo "*** Testing fgetc() : basic operations ***\n";
/* read charecter from different files which are opened in different modes */
$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t");
/* create file with following type of contents */
$file_content_types = array("numeric", "text", "text_with_new_line");
for ($outerloop_counter = 0; $outerloop_counter < count($file_content_types); $outerloop_counter++) {
    echo "--- Outerloop iteration ";
    echo $outerloop_counter + 1;
    echo " ---\n";
    // create file file
    create_files(dirname(__FILE__), 1, $file_content_types[$outerloop_counter], 0755, 1, "w", "fgetc_basic", 1);
    //open the file in different modes and check the working of fgetc
    for ($innerloop_counter = 0; $innerloop_counter < count($file_modes); $innerloop_counter++) {
        echo "-- Innerloop iteration ";
        echo $innerloop_counter + 1;
        echo " of Outerloop Iteration ";
        echo $outerloop_counter + 1;
        echo " --\n";
        // open the file using the $file_modes
        $filename = dirname(__FILE__) . "/fgetc_basic1.tmp";
        // file name that is created by create_files
        echo "-- Testing fgetc() : file opened using {$file_modes[$innerloop_counter]} mode --\n";
        $file_handle = fopen($filename, $file_modes[$innerloop_counter]);
        if (!$file_handle) {
            echo "Error: failed to open file {$filename}!";
            exit;
示例#16
0
 * Source code: ext/standard/dir.c
 */
/*
 * Test scandir() with relative paths as $dir argument
 */
echo "*** Testing scandir() : usage variations ***\n";
// include for create_files/delete_files functions
include dirname(__FILE__) . '/../file/file.inc';
$base_dir_path = dirname(__FILE__);
$level_one_dir_path = "{$base_dir_path}/level_one";
$level_two_dir_path = "{$level_one_dir_path}/level_two";
// create directories and files
mkdir($level_one_dir_path);
create_files($level_one_dir_path, 2, 'numeric', 0755, 1, 'w', 'level_one', 1);
mkdir($level_two_dir_path);
create_files($level_two_dir_path, 2, 'numeric', 0755, 1, 'w', 'level_two', 1);
echo "\n-- \$path = './level_one': --\n";
var_dump(chdir($base_dir_path));
var_dump(scandir('./level_one'));
echo "\n-- \$path = 'level_one/level_two': --\n";
var_dump(chdir($base_dir_path));
var_dump(scandir('level_one/level_two'));
echo "\n-- \$path = '..': --\n";
var_dump(chdir($level_two_dir_path));
var_dump(scandir('..'));
echo "\n-- \$path = 'level_two', '.': --\n";
var_dump(chdir($level_two_dir_path));
var_dump(scandir('.'));
echo "\n-- \$path = '../': --\n";
var_dump(chdir($level_two_dir_path));
var_dump(scandir('../'));
示例#17
0
<?php

/* Prototype  : array scandir(string $dir [, int $sorting_order [, resource $context]])
 * Description: List files & directories inside the specified path 
 * Source code: ext/standard/dir.c
 */
/*
 * Pass different integers as $sorting_order argument to test how scandir()
 * re-orders the array
 */
echo "*** Testing scandir() : usage variations ***\n";
// include for create_files/delete_files functions
include dirname(__FILE__) . '/../file/file.inc';
// create directory and files
$dir = dirname(__FILE__) . '/scandir_variation9';
mkdir($dir);
@create_files($dir, 2);
// different ints to pass as $sorting_order argument
$ints = array(PHP_INT_MAX, -PHP_INT_MAX, 0);
foreach ($ints as $sorting_order) {
    var_dump(scandir($dir, $sorting_order));
}
delete_files($dir, 2);
?>
===DONE===
<?php 
error_reporting(0);
$dir = dirname(__FILE__) . '/scandir_variation9';
rmdir($dir);
/* 
 Prototype   : int filesize ( string $filename );
 Description : Returns the size of the file in bytes, or FALSE 
   (and generates an error of level E_WARNING) in case of an error.
*/
$file_path = dirname(__FILE__);
require $file_path . "/file.inc";
echo "*** Testing filesize(): usage variations ***\n";
echo "\n*** Testing size of a dir, sub-dir and file with filesize() ***\n";
echo "-- Creating a base dir, and checking its size --\n";
mkdir($file_path . "/filesize_variation2");
var_dump(filesize($file_path . "/filesize_variation2"));
clearstatcache();
echo "-- Creating a file inside base dir, and checking dir & file size --\n";
create_files($file_path . "/filesize_variation2", 1, "numeric", 0755, 1, "w", "filesize_variation");
var_dump(filesize($file_path . "/filesize_variation2"));
clearstatcache();
var_dump(filesize($file_path . "/filesize_variation2/filesize_variation1.tmp"));
clearstatcache();
delete_files($file_path . "/filesize_variation2", 1, "filesize_variation");
echo "-- Creating an empty sub-dir in base-dir, and checking size of base and sub dir --\n";
mkdir($file_path . "/filesize_variation2/filesize_variation2_sub");
var_dump(filesize($file_path . "/filesize_variation2"));
// size of base dir
clearstatcache();
var_dump(filesize($file_path . "/filesize_variation2/filesize_variation2_sub"));
// size of subdir
clearstatcache();
echo "-- Creating a file inside sub-dir, and checking size of base, subdir and file created --\n";
// create only the file, as base and subdir is already created
<?php

global $CONFIG;
$data_directory = $CONFIG->dataroot . 'gc_dept' . DIRECTORY_SEPARATOR;
$dbprefix = elgg_get_config("dbprefix");
if (file_exists($data_directory . 'department_directory.json')) {
    $information_array = json_decode(file_get_contents($data_directory . 'department_directory.json'));
    $information_array = get_object_vars($information_array);
    $last_guid_onFile = $information_array['members'];
} else {
    $last_guid_onFile = 0;
}
$last_guid_db = elgg_get_entities(array('types' => 'user', 'limit' => '1'));
if ($last_guid_db[0]->getGUID() != $last_guid_onFile) {
    if ($last_guid_onFile != 0) {
        // backup the files then remove
        rename($data_directory . 'department_directory.json', $data_directory . 'department_directory_' . date("Y-m-d-h-i-s") . '.json');
        unlink($data_directory . 'department_listing.json');
    }
    // create the files
    $result = create_files($data_directory);
}
forward(REFERER);
示例#20
-1
<?php

/*  Prototype: string file_get_contents( string $filename[, bool $use_include_path[,
 *                                       resource $context[, int $offset[, int $maxlen]]]] )
 *  Description: Reads entire file into a string
 */
$file_path = dirname(__FILE__);
include $file_path . "/file.inc";
echo "*** Testing the basic functionality of the file_get_contents() function ***\n";
echo "-- Testing with simple valid data file --\n";
create_files($file_path, 1, "text", 0755, 100, "w", "file", 1, "byte");
var_dump(file_get_contents($file_path . "/file1.tmp"));
delete_files($file_path, 1);
echo "\n-- Testing with empty file --\n";
create_files($file_path, 1, "empty", 0755, 100, "w", "file", 1, "byte");
var_dump(file_get_contents($file_path . "/file1.tmp"));
delete_files($file_path, 1);
echo "\n*** Done ***";
var_dump(is_writeable("{$file_path}/is_writable_variation2"));
// exp: bool(false)
chmod("{$file_path}/is_writable_variation2", 0777);
// chmod to enable deletion of directory
echo "\n*** Testing miscelleneous input for is_writable() function ***\n";
$name_prefix = "is_writable_variation2";
create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 1);
create_files(dirname(__FILE__), 1, "text", 0755, 1, "w", $name_prefix, 2);
create_files(dirname(__FILE__), 1, "empty", 0755, 1, "w", $name_prefix, 3);
create_files(dirname(__FILE__), 1, "numeric", 0555, 1, "w", $name_prefix, 4);
create_files(dirname(__FILE__), 1, "text", 0222, 1, "w", $name_prefix, 5);
create_files(dirname(__FILE__), 1, "numeric", 0711, 1, "w", $name_prefix, 6);
create_files(dirname(__FILE__), 1, "text", 0114, 1, "w", $name_prefix, 7);
create_files(dirname(__FILE__), 1, "numeric", 0244, 1, "w", $name_prefix, 8);
create_files(dirname(__FILE__), 1, "text", 0421, 1, "w", $name_prefix, 9);
create_files(dirname(__FILE__), 1, "text", 0422, 1, "w", $name_prefix, 10);
$misc_files = array("{$file_path}/is_writable_variation21.tmp", "{$file_path}/is_writable_variation22.tmp", "{$file_path}/is_writable_variation23.tmp", "{$file_path}/is_writable_variation24.tmp", "{$file_path}/is_writable_variation25.tmp", "{$file_path}/is_writable_variation26.tmp", "{$file_path}/is_writable_variation27.tmp", "{$file_path}/is_writable_variation28.tmp", "{$file_path}/is_writable_variation29.tmp", "{$file_path}/is_writable_variation210.tmp");
$counter = 1;
/* loop through to test each element in the above array
   is a writable file */
foreach ($misc_files as $misc_file) {
    echo "-- Iteration {$counter} --\n";
    var_dump(is_writable($misc_file));
    var_dump(is_writeable($misc_file));
    $counter++;
    clearstatcache();
}
// change all file's permissions to 777 before deleting
change_file_perms($file_path, 10, 0777, $name_prefix);
delete_files($file_path, 10, $name_prefix);
echo "Done\n";
示例#22
-1
 * Source code: ext/standard/dir.c
 */
/*
 * Pass a directory handle pointing to a directory that has a sub-directory
 * to test behaviour of readdir()
 */
echo "*** Testing readdir() : usage variations ***\n";
// include the file.inc for Function: function create_files()
chdir(dirname(__FILE__));
include dirname(__FILE__) . "/../file/file.inc";
$path_top = dirname(__FILE__) . '/readdir_variation3';
$path_sub = $path_top . '/sub_folder';
mkdir($path_top);
mkdir($path_sub);
create_files($path_top, 2);
create_files($path_sub, 2);
$dir_handle = opendir($path_top);
while (FALSE !== ($file = readdir($dir_handle))) {
    // different OS order files differently so will
    // store file names into an array so can use sorted in expected output
    $contents[] = $file;
}
// more important to check that all contents are present than order they are returned in
sort($contents);
var_dump($contents);
delete_files($path_top, 2);
delete_files($path_sub, 2);
closedir($dir_handle);
?>
===DONE===
<?php 
示例#23
-1
        echo "OK\n";
    } else {
        echo "Error: Expected: {$expect_size}, Actual: {$size}";
    }
}
echo "*** Testing fread() basic operations ***\n";
/* 
 test fread with file opened in "r" and "rb" mode only
 Content with numeric and strings with it 
*/
$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t");
$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
foreach ($file_content_types as $file_content_type) {
    echo "\n-- Testing fread) with file having data of type " . $file_content_type . " --\n";
    /* create files with $file_content_type */
    create_files(dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "fread_basic");
    $filename = dirname(__FILE__) . "/fread_basic1.tmp";
    // this is name of the file created by create_files()
    /* open the file using $files_modes and perform fread() on it */
    for ($inner_loop_counter = 0; $inner_loop_counter < count($file_modes); $inner_loop_counter++) {
        echo "-- File opened in mode " . $file_modes[$inner_loop_counter] . " --\n";
        $file_handle = fopen($filename, $file_modes[$inner_loop_counter]);
        if (!$file_handle) {
            echo "Error: failed to fopen() file: {$filename}!";
            exit;
        }
        /* read file by giving the acutal length, check the length and content by calculating the 
             hash using md5() function 
           */
        /* Reading 1024 bytes from file, expecting 1024 bytes */
        var_dump(ftell($file_handle));
/* Prototype  : string readdir([resource $dir_handle])
 * Description: Read directory entry from dir_handle 
 * Source code: ext/standard/dir.c
 */
/*
 * Open two directory handles on the same directory and pass both
 * to readdir() to test behaviour
 */
echo "*** Testing readdir() : usage variations ***\n";
// include the file.inc for Function: function create_files()
include dirname(__FILE__) . "/../file/file.inc";
// create the temporary directory
$dir_path = dirname(__FILE__) . "/readdir_variation6";
mkdir($dir_path);
// create files within the temporary directory
create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "readdir_variation6");
// open the directory
$dir_handle1 = opendir($dir_path);
// open the same directory again without closing it
opendir($dir_path);
echo "\n-- Reading Directory Contents with Previous Handle --\n";
$a = array();
while (FALSE !== ($file = readdir($dir_handle1))) {
    $a[] = $file;
}
sort($a);
foreach ($a as $file) {
    var_dump($file);
}
echo "\n-- Reading Directory Contents with Current Handle (no arguments supplied) --\n";
$a = array();
示例#25
-1
echo "*** Testing ftruncate() : usage variations ***\n";
/* test ftruncate with file opened in different modes */
$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", "w", "wb", "wt", "w+", "w+b", "w+t", "x", "xb", "xt", "x+", "x+b", "x+t", "a", "ab", "at", "a+", "a+b", "a+t");
$file_content_types = array("numeric", "text_with_new_line");
foreach ($file_content_types as $file_content_type) {
    echo "\n-- Testing ftruncate() with file having data of type " . $file_content_type . " --\n";
    for ($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
        echo "-- Testing ftruncate() with file opening using {$file_modes[$mode_counter]} mode --\n";
        // create 1 file with some contents
        $filename = dirname(__FILE__) . "/ftruncate_variation1.tmp";
        if (strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w")) {
            // fopen the file using the $file_modes
            $file_handle = fopen($filename, $file_modes[$mode_counter]);
            fill_file($file_handle, $file_content_type, 1024);
        } else {
            create_files(dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation");
            // fopen the file using the $file_modes
            $file_handle = fopen($filename, $file_modes[$mode_counter]);
        }
        if (!$file_handle) {
            echo "Error: failed to open file {$filename}!\n";
            exit;
        }
        rewind($file_handle);
        // file pointer to 0
        /* truncate it to size 0 */
        echo "-- Testing ftruncate(): truncate file to size = 0 --\n";
        $new_size = 0;
        var_dump(filesize($filename));
        // check the current file size
        var_dump(ftell($file_handle));
     1. All read and append modes
     2. Testing fseek() without using argument whence 
*/
echo "*** Testing fseek(), ftell(), rewind() : default whence & all r and a modes ***\n";
$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", "a", "ab", "at", "a+", "a+b", "a+t");
$file_content_types = array("text_with_new_line", "alphanumeric");
$offset = array(-1, 0, 1, 513);
// different offsets, including negative and beyond size
$filename = dirname(__FILE__) . "/fseek_ftell_rewind_variation1.tmp";
// this is name of the file created by create_files()
/* open the file using $files_modes and perform fseek(),ftell() and rewind() on it */
foreach ($file_content_types as $file_content_type) {
    echo "\n-- File having data of type " . $file_content_type . " --\n";
    foreach ($file_modes as $file_mode) {
        echo "-- File opened in mode " . $file_mode . " --\n";
        create_files(dirname(__FILE__), 1, $file_content_type, 0755, 512, "w", "fseek_ftell_rewind_variation", 1, "bytes", ".tmp");
        //create a file with 512 bytes size
        $file_handle = fopen($filename, $file_mode);
        if (!$file_handle) {
            echo "Error: failed to fopen() file: {$filename}!";
            exit;
        }
        echo "-- Testing fseek() without using argument whence --\n";
        foreach ($offset as $count) {
            var_dump(fseek($file_handle, $count));
            var_dump(ftell($file_handle));
            // confirm the file pointer position
            var_dump(feof($file_handle));
            //ensure that file pointer is not at end
        }
        //end of offset loop