私はLaravelで画像をアップロードするには、このコードを持っている:laravelとの問題 - str_random
public function store(Requests\ArticleRequest $request)
{
$article['photo']= 'http://nationaluasi.com/dru/content/hotelIcon.png';
$file = array('image' => $request->file('image'));
// setting up rules
$rules = array('image' => 'required',); //mimes:jpeg,bmp,png and for max size max:10000
// doing the validation, passing post data, rules and the messages
$validator = Validator::make($file, $rules);
if ($validator->fails()) {
// send back to the page with the input data and errors
$article['photo'] = null;
}
else {
// checking file is valid.
if ($request->file('image')->isValid()) {
$destinationPath = public_path().'/images'; // upload path
$extension = $request->file('image')->getClientOriginalExtension(); // getting image extension
$article['photo'] = str_random(5).'.'.$extension; // renameing image
$request->file('image')->move($destinationPath, $article['photo']); // uploading file to given path
// sending back with message
}
else {
}
}
$article = new Article($request->all());
$article['key']= str_random(30);
Auth::user()->articles()->save($article);
Alert::success('nnn','Good job!')->persistent("Close");
return redirect('auctions');
}
ので、すべてが画像のアップロードと罰金ですが、私は私の/public/images
画像をフォルダ表示される名前がありますDiYhh.png
をしかし、データベースに格納されています:/tmp/phpVu3QOa
なぜ、プロンプトは何ですか? image
データベースに同じ名前を格納しないでください(DiYhh.png
)/ tmp/... ???
データベースに変更を保存する場所はどこですか?コードスニペットでは、 '$ article ['image']'をファイル名に設定するだけですが、実際にどこに保存するのかは表示されません。 –
これを商品テーブルに保存します - カラムイメージ... – Andrew
そのコードを質問にも追加できますか? –