Download the PHP package popphp/pop-file without Composer
On this page you can find all versions of the php package popphp/pop-file. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popphp/pop-file
More information about popphp/pop-file
Files in popphp/pop-file
Package pop-file
Short Description Pop File Component for Pop PHP Framework
License New BSD
Homepage http://www.popphp.org/
Informations about the package pop-file
pop-file
END OF LIFE
The pop-file
component v2.1.0 is now end-of-life. The upload and dir sub-components have
been forked and pushed into other repositories, respectively:
- popphp/pop-http (now the Pop\Http\Upload class)
- popphp/pop-dir (now the Pop\Dir\Dir class)
OVERVIEW
pop-file
is a component for managing file uploads and easily traversing files
within a directory. With file uploads, you can set fine-grain controls to
manage specific upload parameters like file types and file size. Also, you can
traverse directories recursively as well.
pop-file
is a component of the Pop PHP Framework.
INSTALL
Install pop-file
using Composer.
composer require popphp/pop-file
BASIC USAGE
File uploads
Basic file upload
The above code creates the upload object, sets the upload path and sets the basic defaults, which includes a max file size of 10MBs, and an array of allowed common file types as well as an array of common disallowed file types.
File upload names and overwrites
By default, the file upload object will not overwrite a file of the same name. In the above
example, if $_FILES['file_upload']['name']
is set to 'my_document.docx' and that file
already exists in the upload path, it will be renamed to 'my_document_1.docx'.
If you want to enable file overwrites, you can simply do this:
Also, you can give the file a direct name on upload like this:
And if you need to check for a duplicate filename first, you can use the checkFilename
method. If the filename exists, it will append a '_1' to the end of the filename, or loop
through until it finds a number that doesn't exist yet (_#). If the filename doesn't
exist yet, it returns the original name.
Directory traversal
Traversing a directory
If you want to traverse the directory recursively and get the full path of each file.
The available boolean options for the $options
array parameter are:
- 'absolute' => store the absolute, full path of the items in the directory
- 'relative' => store the relative path of the items in the directory
- 'recursive' => traverse the directory recursively
- 'filesOnly' => store only files in the object (and not other directories)
Emptying a directory
The true
flag will remove the actually directory as well.