Laravel storage link in shared hosting - laravel

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

Just create a route and access it once.
Route::get('generate', function (){
\Illuminate\Support\Facades\Artisan::call('storage:link');
echo 'ok';
});

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';
Go to web site example.com/mysymlink.php

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
Investigate to set a right symlink (This possibility nowadays exist almost everywhere) it should be something like 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.
Try to implement in some workaround way. For example you can try to put files from 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.

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
]);
}

Related

laravel storage method not displaying images on another OS or machine

I store images using this method:
'avatar' => $r->avatar->store('public/avatars')
and get them like
<img src="{{Storage::url($user->avatar)}}" style="border-radius:50%;height:30px;width:30px;" style alt="">
They get displayed on the local machine, but not in others. What could be the issue?
Check the value of user's avatar column, you might have some sort symlinks enabled on local machine, Instead you can also use public_path, as storage should not be exposed outside.
https://laravel.com/docs/5.6/helpers#method-public-path
Also check file visibility
https://laravel.com/docs/5.6/filesystem#storing-files
you have stored file inside public/avatars
be sure $user->avatar has public/avatars concatenated if not you might have to
{{Storage::url("public/avatars/".$user->avatar)}}
use this as source of your image
had to delete the public/storage folder on the other machine then run
php artisan storage:link
images started showing as normal

Why does my Joomla site subdomain copy the main site?

I'm not a pro with server management, I mainly do web design on Joomla.
Our IT Manager recently left and I was given access to everything since no-one else in our company knows web.
We have a main site. In this example I'll name the site as cookies.com for example sake.
www.cookies.com is the main site. The domain is cookies.com only. We have 3 server accounts for this.
123reg - to buy the domain and renew
heartinterner - to host the website
1and1 - this is where it is redirected (or something), well all the files are found in virtual servers here.
When I go to the virtual servers, there are a couple of directories, and eventually I can find a folder called "var" which leads me to another directory. I go to "www" and I find so many site folders there, including cookies.com and dev.cookies.com and more
My objective was to backup and restore cookies.com to dev.cookies.com so that I can work on it and replace the original cookies.com later on. I use Akeeba Backup for this.
The issue is, as soon as I started making changes to dev.cookies.com, cookies.com also made those changes.
I'm very confused- what's going on here? Is there something written in the files that direct the database or whatever to the same place, for which reason the changes occur together?
Sorry this is very confusing. Please suggest if you can what I can do. I know this might not be much information.
Thank you!
You probably have used the same database for both. Create another database and user for dev.cookies.com and use that database and user to create the new dev site. Check in the configuration.php file that these values should be different.
public $db = 'joomla';
public $password = 'db_password';
public $user = 'root';
These are all database values. Also check these settings
public $log_path = 'C:/xampp/htdocs/joomla/administrator/logs';
public $tmp_path = 'C:/xampp/htdocs/joomla/tmp';

how to generate download link Files that are located on another server in laravel

I put my videos on my Shared web host and user can direct download all files. but I want to hide my actual file paths and make time-limited download links.
if files were on same server it is work fine.
when I use this code :
return response()->download('/home2/alihoss1/domains/alihossein.ir/public_html/dl/video/MySql/Sql1.mp4');
i see this error :
is_file(): open_basedir restriction in effect. File(/home2/alihoss1/domains/alihossein.ir/public_html/dl/video/MySql/Sql1.mp4) is not within the allowed path(s): (/home2/alihosse/domains/alihossein.ir/:/tmp/:/usr/local/php-7.0/lib/php/)
What solution would you recommend ؟
videos and laravel Project are not same host.
You could use something like file_get_contents() to get the file from the other server. This would lead to unneccessary traffic though because server 1 would download the file from server 2. That applies also to scp etc.
You should think about encryption:
$hash = encrypt([
'valid_to' => strtotime('+30 minutes'),
'file_path' => '/home2/alihoss1/domains/alihossein.ir/public_html/dl/video/MySql/Sql1.mp4'
]);
return redirect('http://server2.example/download/hash/' . urlencode($hash));
You then need to decrypt this on the second server with the same key. If you do not have laravel installed there, you can implement your own decrypting functionality (see: laravel openssl encryption).

restrict access on public folder in laravel 4.2

im fairly new to laravel and im currently working on a project that needs to store files in the server. What im doing is store it under public/docs the problem is the files under that directory is accessible all the time given that they know the url to the certain file. for example even if they are logged out if they know this url http://localhost/dummy/public/uploads/docs/2016-06-02-10-52-43-oth-content-inventory-and-planning-spreadsheet.pdf they would be able to access it what im thinking is to do something like this
in my routes i would do something like
Route::any('uploads/docs/' , 'go to some controller to check if user can acces');
is this possible? thanks in advance!
it's called public for a reason...
you should use storage instead (laravel 5) in storage you dont restrict access, actualy the opposite, you grant access to the file .
try this for laravel 4.2 (move the file after upload like this to a storage folder)
Input::file('file')->move(__DIR__.'/storage/',Input::file('file')->getClientOriginalName());
});
Anyway ,the conclusion is that you can't restrict access (you shouldn't even if there is a way) because it's meant to be public ! so you should use storage folder(or whatever its called in laravel 4)

How To Use Model Of Another Application in Codeigniter

I am working on a project where I create Two Application hosted in same site.
My structure is given below…
SITE
SYSTEM
APPLICATION
font_end
back_end
Now my question is,is it possible to access model of one application from another application.
As example, I have a model named ‘User_model’ in font_end application. Is it possible to use this model from back_end application.
Thanks.
Yes, it is possible, but there is a but. It doesn't matter where your files are in an absolute sense, but it is not necessarily the easiest thing in the world to accomplish.
Your best bet is to use symlinks if you can and link them into a sub-directory of your models directory. This would be simple and clean.
Barring that, you should extend Loader and overwrite the &model method to look in the secondary directory (perhaps reassign $path to the alternate application's model folder if $path == 'frontend').
If that also isn't an option, loading is done through APPPATH.'models/'.$path . '/' .$model.EXT. This means you can access the model by the relative path to APPPATH.'models/'. Don't do that if you can possibly avoid it, however. It is non-obvious and an invitation to errors.
I tried your last version (error prone I know) and got this result:
Unable to locate the model you have specified: ext.
I used this load code to access the frontend model from my backend:
$this->load->model('APPPATH.'/models/frontend/'Frontend_Model'.'EXT');
apppath and ext constants should be used like variables, but if I put it this way my notepad ++ highlighting goes wrong:
$this->load->model(APPPATH.'/models/hp/'Homepage_Model'.EXT)
admin/application/model/accounts_model.php
application/controller/home.php
Put this code in home.php to use model of admin applicaton
$this->load->model('../../../Unicorn/application/models/accounts_model');

Resources