분류
php
PHP 파일 업로드 및 유효성 검사를 처리하기 위한 라이브러리.
본문
https://github.com/brandonsavage/Upload
이 구성 요소는 파일 유효성 검사 및 업로드를 단순화합니다.
HTML :
<form method="POST" enctype="multipart/form-data"> <input type="file" name="foo" value=""/> <input type="submit" value="Upload File"/> </form>
PHP :
<?php $storage = new \Upload\Storage\FileSystem('/path/to/directory'); $file = new \Upload\File('foo', $storage); // Optionally you can rename the file on upload $new_filename = uniqid(); $file->setName($new_filename); // Validate file upload // MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml $file->addValidations(array( // Ensure file is of type "image/png" new \Upload\Validation\Mimetype('image/png'), //You can also add multi mimetype validation //new \Upload\Validation\Mimetype(array('image/png', 'image/gif')) // Ensure file is no larger than 5M (use "B", "K", M", or "G") new \Upload\Validation\Size('5M') )); // Access data about the file that has been uploaded $data = array( 'name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions() ); // Try to upload file try { // Success! $file->upload(); } catch (\Exception $e) { // Fail! $errors = $file->getErrors(); }
- 이전글PHP OAuth 2.0 서버 19.01.18
- 다음글PHP 간단한 유효성 검사 라이브러리 19.01.18