0

When I uploaded some videos via a form it saved my videos on the public folder but in the view I can't access them.

my view (tyring to output the filepath)

    <td>{{ $media->video_ogg}} </td>
    <td>{{ $media->video_mp4}} </td>

result

C:\Users\Jeffrey\AppData\Local\Temp\phpBB7C.tmp
C:\Users\Jeffrey\AppData\Local\Temp\phpBB7C.tmp

it supposed to be on a different path (my project path).

On my local computer on the videos folder I can see that the videos was uploaded.

enter image description here

Mycontroller.php

    public function store(Request $request)
   {
      // Validation //
      $validation = Validator::make($request->all(), [
         'about_me' => 'required',
         'video_ogg'    => 'required|mimes:mp4,ogx,oga,ogv,ogg,webm|min:1|max:3240',
         'video_mp4'    => 'required|mimes:mp4,mov,ogg,qt,webm|min:1|max:3240'
      ]);

      // Check if it fails //
      if( $validation->fails() ){
         return redirect()->back()->withInput()
                          ->with('errors', $validation->errors() );
      }

      $profile = new Profile;

      // upload the media //
      $file = $request->file('video_ogg');
      $destination_path = 'videos/';
      $filename = str_random(6).'_'.$file->getClientOriginalName();
      $file->move($destination_path, $filename);

      // upload the media //
      $file = $request->file('video_mp4');
      $destination_path = 'videos/';
      $filename = str_random(6).'_'.$file->getClientOriginalName();
      $file->move($destination_path, $filename);

      // save media data into database //
      $profile->about_me = $request->input('about_me');
      $profile->video_mp4 = $request->file('video_mp4');
      $profile->video_ogg = $request->file('video_ogg');
      $profile->save();

      return redirect('/profile')->with('message','You just created your profile!');
   }

file permission (on Windows powershell)

enter image description here

So how can I can get the right path on the view?

because it supposed to be : videos/QvWjJ2_mov_bbb.mp4 and videos/muWzE9_mov_bbb.ogg

Papouche Guinslyzinho
  • 5,277
  • 14
  • 58
  • 101
  • Where does the $media object for the view come from? – Chris Baldwin Jul 23 '17 at 05:58
  • hi @ChrisBaldwin this variable is wrongly name :( my bad! ... but on the View I have this `@foreach($profiles as $media)` that's why I have the `$media` on the View and on my **index** controller I do have this `return view('profiles.profiles-list')->with('profiles', $profiles);` I will change the variable name for **$profile** – Papouche Guinslyzinho Jul 23 '17 at 06:02

2 Answers2

0

Try like this:

<td>{{  url('/') }}{{ YOUR_FILE_PATH_AFTER_PUBLIC }}</td>

<td>{{  url('/') }}{{ YOUR_FILE_PATH_AFTER_PUBLIC }}</td>

Eg: Send path from controller to view using compact like this:

   $path = '/videos/muWzE9_mov_bbb.ogg';

   $path1 = '/videos/QvWjJ2_mov_bbb.mp4';

   return view('VIEW_PATH',compact('path','path1'));

In View:

<td>{{  url('/') }}{{ $path }}</td>

<td>{{  url('/') }}{{ $path1 }}</td>
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
0

To start with when you save the uploaded files you add a random string to the file name. You don't seem to save this random filename anywhere so that is going to make it hard to find the files later. You probably want to add those filenames to the profile object you save in the database.

After that your controller can build the URLs

$ogg_path = 'videos/' . $profile->ogg_filename;
$mp4_path = 'videos/' . $profile->mp4_filename;

Then in the view

{{ url($ogg_path) }}
{{ url($mp4_path) }}
Chris Baldwin
  • 539
  • 3
  • 9