store() isn't uploading a file

Published 1 week ago by jerauf

I've got this code from my file upload form.

    $file_name = $request->file('file_name');
            
    $path = $request->file('file_name')->store('uploads');

The uploads folder is set to read/write access 777. If I return $path, it gives me the right path and the new name of the file. But the file isn't on me server.

I've also tried:

     $path = Storage::putFile('uploads', $request->file('file_name'));

That hasn't worked either.

What am I doing wrong?

Dry7
Dry7
1 week ago (124,820 XP)

@jerauf <form> tag contains

 <form enctype="multipart/form-data" method="POST">

?

Dry7

@jerauf <form> tag contains

 <form enctype="multipart/form-data" method="POST">

?

jerauf

@Dry7 -

Yeah, my form is:

    <form action="{{ route('saveFile') }}" method="post" enctype="multipart/form-data">
    
    <input type="file" name="file_name">
    
    <p><button type="submit">Upload</button>
    
    {{ csrf_field() }}
    
    </form>
Dry7
Dry7
1 week ago (124,820 XP)

@jerauf what returns

print_r($_FILES);

?

Dry7

@jerauf what returns

print_r($_FILES);

?

jerauf

Sure. It's:

 Array ( [file_name] => Array ( [name] => the_big_w.jpg [type] => image/jpeg [tmp_name] => /tmp/php7wwiqj [error] => 0 [size] => 190115 ) )
Dry7
Dry7
1 week ago (124,820 XP)

@jerauf check /storage/app/uploads and /storage/uploads

Dry7

@jerauf check /storage/app/uploads and /storage/uploads

jerauf

They're there! In storage/app/uploads

Thank you.

jerauf

However, when I try to access the file, I'm given an error:

 File `storage/app/uploads/8UpdkvL3QsiDu3oh3qILd9GO7Exhtpm9IgnnnUUr.jpeg` does not exist

And when I go to domain.com/storage/app/uploads/8UpdkvL3QsiDu3oh3qILd9GO7Exhtpm9IgnnnUUr.jpeg, I get a page not found error.

Dry7
Dry7
1 week ago (124,820 XP)

@jerauf run

php artisan storage:link

save file to

 $path = $request->file('file_name')->store('public/uploads');

and use domain.com/storage/uploads/8UpdkvL3QsiDu3oh3qILd9GO7Exhtpm9IgnnnUUr.jpeg

Dry7

@jerauf run

php artisan storage:link

save file to

 $path = $request->file('file_name')->store('public/uploads');

and use domain.com/storage/uploads/8UpdkvL3QsiDu3oh3qILd9GO7Exhtpm9IgnnnUUr.jpeg

jerauf

Same result after doing that and going to domain.com/storage/app/uploads/8UpdkvL3QsiDu3oh3qILd9GO7Exhtpm9IgnnnUUr.jpeg

Sign In or create a forum account to participate in this discussion.