我有這樣的代碼上傳圖像與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
您可以將該代碼添加到問題中嗎? –