Doubt storageAs Laravel 5.4

Asked

Viewed 130 times

0

I was with my local Laravel project, and I use this code to save my images:

$request->profile_photo->storeAs('empresas/perfil', $filename, 'public');

Now I hosted my project, to host I needed to take out the folder public from the root of the project, it stays at the same level of the project and is called public_html.

When saving an image shows the following error:

(1/1) Errorexception fopen(/Storage/ssd3/972/3511972/public_html): failed to open stream: Is a directory in Filesystemadapter.php (line 160) At Handleexceptions->handleError(2, 'fopen(/Storage/ssd3/972/3511972/public_html): failed to open stream: Is a directory', '/Storage/ssd3/972/3511972/Laravel/vendor/Laravel/framework/src/Illuminate/Filesystem/Filesystemadapter.php', 160, array('path' => '../companies/profile', 'file' => Object(Uploadedfile), 'name' => 'Laravel_foto_perfiliuyuieatwaygmailcom_teste.jpg', 'options' => array()) at fopen('/Storage/ssd3/972/3511972/public_html', 'r+') in Filesystemadapter.php (line 160)

What I need to change to fix the problem??

  • You have configured the filesystem.php in the briefcase config? and gave write permission in folders?

  • 'disks' => [
 'local' => [
 'driver' => 'local',
 'root' => storage_path('app'),
 ],

 'public' => [
 'driver' => 'local',
 'root' => storage_path('app/public'),
 'url' => env('APP_URL').'/storage',
 'visibility' => 'public',
 ],
 I think the problem is right here, as I do for him to get a folder that is not at the root of the project?

  • storage_path('app/public') shouldn’t be storage_path('app/public_html') when setting changes have to be careful with the total.

  • I made that change, and I tried several others and nothing, continues with the same mistake.

  • Gave permission ... ???

1 answer

-1

Most likely your error, just like it was with me, is related to the size of the image you are sending to the server.

php has the configuration file called php.ini and it contains some settings such as the maximum file size (upload_max_filesize, where the default value is 2MB) and the maximum size of the request made using the POST method (post_max_size, where the default value is 8MB).

If your image is larger than these settings the file will not be available for you to handle or save.

That way, the error happens when the fopen is called internally by the method storeAs and uses the real path of the image ($file->getRealPath()) not available because of the image size limitation.

  • Try to further detail your answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.