Laravel Project Deployment Problem in Shared Hosting (000webhost)
I have Deployed a Laravel Project on a shared hosting "www.000webhost.com".
But There is some problem here that I'm facing now. The Problems are:
- Image Upload (Images are not storing in database & public folder)
- Mail Not sending.
Can anyone please give me the solution...?
if ($request->hasfile('avatar')){
$image = $request->file('avatar');
$filename = time() . 'pp.' . $image->getClientOriginalExtension();
$location = base_path().'/images/' . $filename;
Image::make($image)->save($location);
$user->avatar = $filename;
}
try public_path() and not base_path()
if you have installed Laravel securely, base_path() . '/images/' should not be accessible to users
@snapey
I have also tried this. And its working on localhost, but not in webhost..
$user = User::find(Auth::user()->id);
if($request->hasFile('avatar')){
$path = time().'.'.$request->avatar->getClientOriginalExtension();
$request->avatar->move(public_path('images'), $path);
$user->avatar = $path;
}
You are going to have to investigate what 'not working' means in more detail?
Any errors logged?
Do you go inside the if statement?
is public_path('images') writeable by the web server?
@snapey ,
No. it's not triggering the if condition. And, the public_path('images') aren't writeable by the server
@NIKHIL_LU210 - I think the issue is with the .htacess file, it depends on how u hosted the application.
@gurur
this is my .htaccess file code:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
no, unlikely .htaccess
anyway, you said, server cannot write to public folder.
@snapey yes..
What shoud I do now...?
the public_path('images') aren't writeable by the server
Email the host asking to give you permissions or maybe try to upload the files to an AWS S3 bucket? lol
Please or to participate in this conversation.