Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

file_exists(3) [php man page]

FILE_EXISTS(3)								 1							    FILE_EXISTS(3)

file_exists - Checks whether a file or directory exists

SYNOPSIS
bool file_exists (string $filename) DESCRIPTION
Checks whether a file or directory exists. PARAMETERS
o $filename - Path to the file or directory. On windows, use //computername/share/filename or \computernamesharefilename to check files on network shares. RETURN VALUES
Returns TRUE if the file or directory specified by $filename exists; FALSE otherwise. Note This function will return FALSE for symlinks pointing to non-existing files. Warning This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir. Note The check is done using the real UID/GID instead of the effective one. Note Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB. EXAMPLES
Example #1 Testing whether a file exists <?php $filename = '/path/to/foo.txt'; if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } ?> ERRORS
/EXCEPTIONS Upon failure, an E_WARNING is emitted. NOTES
Note The results of this function are cached. See clearstatcache(3) for more details. Tip As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to "Supported Protocols and Wrappers" to determine which wrappers support stat(3) family of functionality. SEE ALSO
is_readable(3), is_writable(3), is_file(3), file(3). PHP Documentation Group FILE_EXISTS(3)

Check Out this Related Man Page

MOVE_UPLOADED_FILE(3)							 1						     MOVE_UPLOADED_FILE(3)

move_uploaded_file - Moves an uploaded file to a new location

SYNOPSIS
bool move_uploaded_file (string $filename, string $destination) DESCRIPTION
This function checks to ensure that the file designated by $filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by $destination. 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. PARAMETERS
o $filename - The filename of the uploaded file. o $destination - The destination of the moved file. RETURN VALUES
Returns TRUE on success. If $filename is not a valid upload file, then no action will occur, and move_uploaded_file(3) will return FALSE. If $filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file(3) will return FALSE. Additionally, a warning will be issued. EXAMPLES
Example #1 Uploading multiple files <?php $uploads_dir = '/uploads'; foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "$uploads_dir/$name"); } } ?> NOTES
Note move_uploaded_file(3) is both safe mode and open_basedir aware. However, restrictions are placed only on the $destination path as to allow the moving of uploaded files in which $filename may conflict with such restrictions. move_uploaded_file(3) ensures the safety of this operation by allowing only those files uploaded through PHP to be moved. Warning If the destination file already exists, it will be overwritten. SEE ALSO
is_uploaded_file(3), rename(3), See Handling file uploads for a simple usage example. PHP Documentation Group MOVE_UPLOADED_FILE(3)
Man Page