現状、アップロードした画像はpublicフォルダに格納されており、第三者でも閲覧できてしまいます。
こちらをstorageフォルダに格納することで、ログインしているユーザーなら誰でも閲覧できるよう修正したいです。
アップロード画像は、storageへはstorage_path()を利用して格納することができました。
現在の課題は、こちらの表示についてとなります。
php
1 public function update(Request $request, $id) 2 { 3 $input = $request->all(); 4 5 //画像を追加 6 $files = $request->file('photos'); 7 //配列の中身確認用のjudge変数 http://qiita.com/wonda/items/b4a425edd73880a13e62 8 $judge = array_filter($files); 9 if(!empty($judge)) { 10 $i = 1; 11 foreach ($files as $file) { 12 13 $name = time() . $file->getClientOriginalName(); 14 $file = $file->move(storage_path() . '/images/'.$id,$name); 15 16 $photo = InvPhoto::create(['file'=>$name, 17 'type'=> 1, 18 'inventory_id'=>$id, 19 'number'=>$i]); 20 21 $i++; 22 } 23 }
view側で下記の用にしてみたのですが、参照先に不備があり表示ができません。
<img src="C:\xampp\htdocs\projectname\storage/images/2171/test_pic.jpg" alt="" class="img-responsive img-rounded">
php
1 2 <div class="form-group"> 3 4 @foreach($invphotos as $photo) 5 @if($photo->number == 1) 6 <img src="{{storage_path() }}/images/{{ $photo->file ? $inventory->id.'/'.$photo->file : 'http://placehold.it/400x400' }}" alt="" class="img-responsive img-rounded"> 7 @else 8 <img height="100" src="/images/{{ $photo->file ? $inventory->id.'/'.$photo->file : 'http://placehold.it/50x50' }}" alt="" class="img-rounded"> 9 @endif 10 @endforeach 11 </div>
表示方法についてご教示いただけませんでしょうか。
いつもありがとうございます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/27 10:58
2016/08/27 11:08