Exemple #1
0
            exit;
        }
        if (strstr($file_mode, "w") || strstr($file_mode, "x")) {
            fill_file($file_handle, $file_content_type, 1024);
        }
        rewind($file_handle);
        echo "-- Reading entire file content, expeceted : 0 bytes --\n";
        // read from file, by giving the file actual size,
        $data_from_file = check_read($file_handle, 1024, strstr($file_mode, "+") ? 1024 : 0);
        // calculate the hash and dump it, if data read, expecting here no data was read
        if ($data_from_file != false) {
            var_dump(md5($data_from_file));
        }
        // reading file by giving less than its size
        echo "-- Reading file content less than max. file size, expeceted : 0 bytes --\n";
        rewind($file_handle);
        $data_from_file = check_read($file_handle, 1000, strstr($file_mode, "+") ? 1000 : 0);
        // calculate the hash and dump it, if data read, expecting here no data was read
        if ($data_from_file != false) {
            var_dump(md5($data_from_file));
        }
        // now close the file
        fclose($file_handle);
        // delete the file created
        delete_file($filename);
        // delete file
    }
    // end of inner foreach loop
}
// end of outer foreach loop
echo "Done\n";
        if (strstr($file_mode, "w") || strstr($file_mode, "x")) {
            $data_to_be_written = "";
            fill_file($file_handle, $file_content_type, 1024);
        }
        rewind($file_handle);
        // read file by giving size more than its size
        echo "-- Reading beyond filesize, expeceted : 1024 bytes --\n";
        rewind($file_handle);
        $data_from_file = check_read($file_handle, 1030, strstr($file_mode, "+") ? 1024 : 1024);
        if ($data_from_file != false) {
            var_dump(md5($data_from_file));
        }
        rewind($file_handle);
        echo "-- Reading beyond filesize when file pointer pointing to EOF, expeceted : 0 bytes --\n";
        // try fread when file pointer at end
        fseek($file_handle, 0, SEEK_END);
        //reading file when file pointer at end
        $data_from_file = check_read($file_handle, 10, 0);
        if ($data_from_file != false) {
            var_dump(md5($data_from_file));
        }
        // now close the file
        fclose($file_handle);
        // delete the file created
        delete_file($filename);
        // delete file
    }
    // end of inner foreach loop
}
// end of outer foreach loop
echo "Done\n";