This is a discussion on Filesystem Object in PHP within the PHP Programming forums, part of the Web Development category; flock() example PHP Code: <?php $fp = fopen("/tmp/lock.txt", "w+"); if (flock($fp, ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| flock() example PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| Sponsored Links |
| |||
| flock() will not work on NFS and many other networked file systems. Check your operating system documentation for more details. On some operating systems flock() is implemented at the process level. When using a multithreaded server API like ISAPI you may not be able to rely on flock() to protect files against other PHP scripts running in parallel threads of the same server instance! flock() is not supported on antiquated filesystems like FAT and its derivates and will therefore always return FALSE under this environments (this is especially true for Windows 98 users).
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells. No tilde expansion or parameter substitution is done.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Valid flags:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Convenient way how glob() can replace opendir() PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| ftell() Returns the position of the file pointer referenced by handle; i.e., its offset into the file stream. For e.g PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| From the above example the file pointer must be valid, and must point to a file successfully opened by fopen() or popen(). ftell() gives undefined results for append-only streams (opened with "a" flag).
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| fstat() gathers the statistics of the file opened by the file pointer handle. This function is similar to the stat() function except that it operates on an open file pointer instead of a filename. For example PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| To get of the owner of the file the we can use fileowner() Returns the user ID of the owner of the file, or FALSE in case of an error. The user ID is returned in numerical format, use posix_getpwuid() to resolve it to a username. As of PHP 5.0.0 this function can also be used with some URL wrappers
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| example for displaying full permissions on the files: PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| The function fscanf() is similar to sscanf(), but it takes its input from a file associated with handle and interprets the input according to the specified format, which is described in the documentation for sprintf(). If only two parameters were passed to this function, the values parsed will be returned as an array. Otherwise, if optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference. Any whitespace in the format string matches any whitespace in the input stream. This means that even a tab \t in the format string can match a single space character in the input stream.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| fscanf() Example PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| is_uploaded_file() tells whether the file was uploaded via HTTP POST This is useful to help ensure that a malicious user hasn't tried to trick the script into working on files upon which it should not be working--for instance, /etc/passwd.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system. For proper working, the function is_uploaded_file() needs an argument like $_FILES['userfile']['tmp_name'], - the name of the uploaded file on the clients machine $_FILES['userfile']['name'] does not work.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| is_uploaded_file() example PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| is_uploaded_file() is available only in versions of PHP 3 after PHP 3.0.16, and in versions of PHP 4 after 4.0.2. If you are stuck using an earlier version, you can use the following function to help protect yourself: PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| File Upload Form Code: <!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
__________________ With, J. Jeyaseelan Everything Possible |