私は自分のプロジェクトでSlim 3 Frameworkを使用しており、3 つの入力を持つフォームがあります'file', 'name', 'firstname'
。
$request
私のフォームのデータ入力があると仮定して、アップロードされたファイルを取得するには、このコードを使用します
$files = $request->getUploadedFiles();
if (empty($files['file'])) {
throw new Exception('Invalid image');
}
$newfile = $files['file'];
次に、入力フォームを検証するために、Respect\Validation Libraryを使用します
$validation = $this->validator->validate($request, [
'file' => v::file()->mimetype('application/pdf'),
'name' => v::stringType()->notEmpty()->length(2, 50)->alpha(),
'firstname' => v::stringType()->notEmpty()->length(2, 50)->alpha()
]);
if($validation->failed() {
//...
}
実際には、ファイルの検証は常に失敗します:
var_dump($request->getParam('file')); //return NULL
var_dump($newfile); //return the following
$newfile
コンテンツ
object(Slim\Http\UploadedFile)#59 (8) {
["file"]=> string(14) "/tmp/php409Uje"
["name":protected]=> string(47) "Myfile.pdf"
["type":protected]=> string(15) "application/pdf"
["size":protected]=> int(1404476) ["error":protected]=> int(0)
["sapi":protected]=> bool(true) ["stream":protected]=> NULL
["moved":protected]=> bool(false)
}
だから今私は立ち往生しています。$newfile MIMETYPE
「ファイル」入力を検証するようにバリデーターに指示する方法が本当にわかりません。