Reputation: 89
im having problem with setting up storage link on shared hosting. Because of that I can't upload any image to storage folder in shared hosting
Upvotes: 9
Views: 22977
Reputation: 191
Remove storage folder in public_html/public/storage if you perfomed storage:link in local
then Create a php file for example mysymlink.php in public_html folder
Add below code to mysymlink.php file
<?php
$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($targetFolder,$linkFolder);
echo 'Symlink completed';
Upvotes: 13
Reputation: 320
Just create a route and access it once.
Route::get('generate', function (){
\Illuminate\Support\Facades\Artisan::call('storage:link');
echo 'ok';
});
Upvotes: 16
Reputation: 1427
Using Laravel in shared hosting environment probably not the best decision. Some many good options are now available for the same price and you just need to put a bit of effort to understand how to work with them, even if you have no prior experience. You can use DigitalOcean, Linode, Vultr or many more and it will save you a ton of time.
In case you for some reason still want to use shared hosting and to actually answer your question you can
ln -s /home/user/laravel/storage/app/public /home/user/public_html/storage
. Of course it should by your path which can be different depending of your hosting structure, you should be able to figure out it yourself.storage
to storage/app/public
folder manually (you even can latter automate it by using some script). But workarounds product new workarounds, better not do it hard and wrong way but instead use simple and right even if it seems hard for you at first glance.Upvotes: 3
Reputation: 2610
Instead of using Storage facade, you can use custom method to upload file to your public directory
if($request->has('image')){
$img = $request->file('image');
$ext = $img->getClientOriginalExtension();
$name = time().'.'.$ext;
$path = public_path('\img\uploads');
$img->move($path, $name);
User::where('id', $user->id)->update([
'image' => $name
]);
}
Upvotes: 2