サインアップ プロセスの一環として、ユーザーに画像をアップロードしてもらう必要があります。
コントローラーで $_FILES['filename'] にアクセスしようとしましたが、スリムでは未定義であることが判明しました。
いくつかの記事で Slim のファイル アップロード方法について見たことがあり、それらは機能していると報告されていましたが、私は壁にぶつかりました。
小枝部分はBootstrap File Input ライブラリで正常に動作します
Slim用ファイルアップロードライブラリを利用したサーバー部分の場合
コントローラーコード (AccountController への変更) は次のようになります
...
$storage = new \Upload\Storage\FileSystem('c:/xampp/htdocs/userfrosting/public/images/');
$file = new \Upload\File('imagefile', $storage);
$new_filename = 'test.jpg';
$file->setName($new_filename);
$file->addValidations(array(
// Ensure file is of type "image/jpg"
new \Upload\Validation\Mimetype('image/jpg'),
// Ensure file is no larger than 500K (use "B", "K", M", or "G")
new \Upload\Validation\Size('500K')
));
// Access data about the file that has been uploaded
$uploadfiledata = array(
'name' => $file->getNameWithExtension(),
'extension' => $file->getExtension(),
'mime' => $file->getMimetype(),
'size' => $file->getSize(),
'md5' => $file->getMd5(),
'dimensions' => $file->getDimensions()
);
error_log('$uploadfiledata' . print_r($uploadfiledata, true));
// Try to upload file
try {
// Success!
$file->upload();
} catch (\Exception $e) {
// Fail!
$errors = $file->getErrors();
}
...
これにより、次のエラーが返されます。
タイプ: InvalidArgumentException
メッセージ: キーで識別されるアップロードされたファイルが見つかりません: imagefile
ファイル: C:\xampp\htdocs\userfrosting\userfrosting\vendor\codeguy\upload\src\Upload\File.php
ライン: 139
関連する小枝のチャンクは
<input id="imagefile" type="file" name="imagefile" class="file" data-show-upload="false">
Userfrosting コードの一部としてファイルのアップロードを機能させることができた人はいますか?
ヘルプ/ポインタに感謝します。
ありがとう!