ユーザーにサインアッププロセスの一環としてイメージをアップロードさせる必要があります。File Upload in Userfrosting
コントローラで$ _FILES ['filename']にアクセスしようとしましたが、これはスリムでは定義されていません。
Slimのファイルアップロードの方法について、いくつかの記事が掲載されていましたが、これは機能していると報告されていますが、私は壁に衝突しました。
枝部はFile Upload library for Slim
コントローラコード(AccountControllerの修正)を使用して、サーバ部分についてBootstrap File Input library
で正常に動作し、この
...
$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();
}
...
ように見えるこれは、次のエラーを返し、
タイプ:InvalidArgumentE xception
メッセージ:画像ファイル
ファイル:C:\ xamppの\ htdocsに\ userfrosting \ userfrosting \ベンダ\ codeguy \アップロード\ SRC \アップロード\ File.php
キーで識別されるアップロードされたファイルが見つかりません。ライン:139
関連小枝チャンクが
<input id="imagefile" type="file" name="imagefile" class="file" data-show-upload="false">
ですが、誰でもファイルUPLOを取得することができました広告はUserfrostingコードの一部として機能しますか?
ヘルプ/参考情報を参考にしてください。
ありがとうございます!
この行は、次の行です: '$ file = new \ Upload \ File( 'imagefile'、$ storage);'? – alexw
ありがとう!いいえ、それは '#0 C:\ xampp \ htdocs \ userfrosting \ userfrosting \ controllers \ AccountController.php(424)です:Upload \ File-> __ construct( 'imagefile'、Object(Upload \ Storage \ FileSystem))'トレースのライン)。 – Spurgeon
はこちらのファイル/行です - [リンク] https://github.com/brandonsavage/Upload/blob/develop/src/Upload/File.php#L139 – Spurgeon