Reputation: 17383
I'm developing my application on localhost and I transfer it into server side.
I have a problem with $path
:
$request->file('video')->move($path, $video);
on localhost I must use:
$request->file('video')->move(
public_path().'/assets/videos/tutorials\/', $video
);
//the result of path on server side :"/home/yekidehi/demo/public/assets/videos/tutorials/"
but on server side I must use:
$request->file('video')->move(
'assets/videos/tutorials/', $video
);
//the result of path on server side: 'mydomain.com/assets/video/tutorials/'
It takes a lot of time for me. because everytime that I want to upload my codes on server, I must change $path
.
Is there any solutions?
Upvotes: 0
Views: 1019
Reputation: 138
You can put if condition to check that environment is localhost or not,
if ($_SERVER['HTTP_HOST'] == "localhost") {
$path=public_path().'/assets/videos/tutorials\/';
}
else{
$path='assets/videos/tutorials/';
}
$request->file('video')->move($path, $video);
if condition will work for localhost and else part run when it is live server. hope you will understand.
Thank you
Upvotes: 1