本文整理汇总了PHP中create_files函数的典型用法代码示例。如果您正苦于以下问题:PHP create_files函数的具体用法?PHP create_files怎么用?PHP create_files使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_files函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
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));
示例2: elgg_get_config
<?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);
示例3: fclose
[, 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));
示例4: dirname
<?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);
示例5: dirname
<?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 ---";
示例6: fgetc
<?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));
示例7: filesize
<?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";
示例8: dirname
* 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: fgets
/*
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
示例10: scandir
<?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===
示例11: rewinddir
* 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())) {
示例12: dir
<?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());
示例13: dirname
// 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";
示例14: fgetc
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;
示例15: scandir
* 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('../'));