Unable to probe video laravel ffmpeg - laravel

I have been following this tutorial on https://github.com/pascalbaljetmedia/laravel-ffmpeg and I am trying to resize my video files and it wont do it. I am constantly getting unable to probe. Whats wrong? Here is my code
$vid = $request->file('vive');
$filename = uniqid().$vid->getClientOriginalName();
$vid = $request->file('vive');
$ffmpeg = FFMpeg\FFMpeg::create([
'ffmpeg.binaries' => "/ffmpeg.exe",
'ffprobe.binaries' => "/ffprobe.exe"
]);
FFMpeg::open($filename)
->addFilter(function ($filters) {
$filters->resize(new \FFMpeg\Coordinate\Dimension(140, 80));
});

The package uses your filesystem.php config file to determine the location of where it is opening the file from. For example, the local disk points to your storage/app path, as defined in the config:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
If you wanted, you could set up a new "disk" in the config that points to the app/ directory (where your file is being saved), though I wouldn't recommend this approach. Your best bet would be to configure PHP to upload your files directly to the storage directory.
Alternatively, you can simply store your file in the storage directly from the input object:
$filename = Input::file('vive')->getClientOriginalName();
$storagePath = 'uploads/temp';
if (!Storage::exists($storagePath)) {
Storage::makeDirectory($storagePath);
}
Input::file('vive')->storeAs($storagePath, $filename);
FFMpeg::fromDisk('local')->open($storagePath . '/' . $filename)->addFilter(function ($filters) {
$filters->resize(new \FFMpeg\Coordinate\Dimension(140, 80));
});

Related

Laravel Symoblic link not working on shared hosting

I modified the using filesystem configuration as
'local' => [
'driver' => 'local',
'root' => public_path('images'),
'throw' => false,
],
So on local system, I'm storing the all the files in public directory
localhost:8000/public/images
by using file upload
$this->logo->storeAs('brand', 'abc.jpg');
I can directly access images using
url('images')
but when i upload my project to live, images are not displaying. I tried and executed the following route, but fail to load images on live server
Route::get('/link', function () {
$target = public_path();
$link = $_SERVER['DOCUMENT_ROOT'] . '/new';
if (symlink($target, $link))
die("SUCCESS");
else
die("ERROR");
});

Laravel server, upload to public_html rather than upload in project folder

I've been trying surfing around this site looking for answers, but nothing works for me, i want to upload an image that save in public_html folder, instead of saving it in project folder (i seperate the project folder and put all public file in public_html folder). Already bind the public.path but it returns to my project folder, not public_html one.
My image upload controller
public static function uploadSubmit($request, $type, $for)
{
if($request->hasFile('photos'))
{
$allowedfileExtension=['jpg','png'];
$files = $request->file('photos');
foreach($files as $file)
{
$extension = $file->getClientOriginalExtension();
$check=in_array($extension,$allowedfileExtension);
//dd($check);
if($check)
{
$idx = Image::create([
'type' => $type,
'ids' => $for,
'ext' => $extension,
])->id;
$filename = $idx . '.' . $file->getClientOriginalExtension();
$filename = $file->storeAs(public_path('images/'), $filename);
}
}
}
}
i already do the public path bind like this in public_html/index.php
$app->bind('path.public', function() {
return __DIR__;
});
Thank you!
First, add config to filesystem.php on config folder:
'disks' => [
...
'public_html' => [
'driver' => 'local',
'root' => public_path(),
'visibility' => 'public',
],
...
],
Second, store image with code:
$file->storeAs('images', $filename, 'public_html')
P/S: Remember to configure the correct path for the public_html directory:
$app->bind('path.public', function(){
return __DIR__.'/../../public_html';
});
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public.
When using the local driver, all file operations are relative to the root directory defined in your filesystems configuration file. By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt:
Storage::disk('local')->put('file.txt', 'Contents');
Or in your case in storage/app/images/file.txt
$file->storeAs(public_path('images/'), $filename);
You can change where these files are stored by changing the filesystems configuration file.
'local' => [
'driver' => 'local',
'root' => public_path(),
],

move uploaded file to root/public_html

i have a laravel project and its uploaded on a sharing host
i have this code for moving uploaded file to folder :
$request->file->move(public_path('images\banners'), $new_name);
my website is like :
root/
laravel
public_html
i just want to move uploaded file to public_html folder
public function register()
{
//
$this->app->bind('path.public', function() {
return realpath(base_path().'/../public_html');
});
}
i try this but its not working
The laravel way is to use FlySystem. Open up config/filesystems.php and add a new entry for public_html.
'disks' => [
'public_html' => [
'driver' => 'local',
'root' => '/full/path/to/public_html',
],
...
Then use it as Storage::disk('public_html')->put('filename', 'contents');. There are other methods on the docs on how to move or upload files to a specific storage here https://laravel.com/docs/5.8/filesystem.
Additionally, instead of specifying the fullpath you can use helper functions such as storage_path() or public_path() depending on where your directory is.
$file = $request->file('image');
$extension = $file->getClientOriginalExtension(); // getting image extension
$filename =time().'.'.$extension;
$path = $file->move(public_path('uploads'), $filename);
$newPath = explode('\public\\', $path);
$filePath = end($newPath);

How i can upload image to public folder in shared hosting laravel 5

I moved my website from localhost to shared hosting all it's good, but i need when i upload file stored directly to public_html: something like this
public_html/storage/
I tried use somenthing like :
symlink('/home/abdoweb/bmcelarave/storage/app/public', '/bmce/public_html/storage')
the problem still exists.
my Controller :
public function addcategory(Request $request){
$title = $request->input('category_name');
$image = $request->file('category-image');
$name = $image->getClientOriginalName();
$image->move(storage_path().'/app/public/category',$name);
$data[] = $name;
$query= DB::table('category')->insert(
[
'title' => $title,
'image' => $name,
"created_at" => Carbon::now()
]);
if($query){
return redirect('categories');
}
}
My folder :
home/abdoweb/{bmcelaravel} <= my public folder
Core laravel :
home/{bmce} <= core laravel
Thank you.
You can a use storage driver :
Inside config/filesystems.php :
'disks' => [
'public' => [
'driver' => 'local',
'root' => public_path() . '/uploads',
'url' => env('APP_URL').'/public',
'visibility' => 'public',
]
]
//Now you can move the file to storage like :
Storage::disk('public')->putFile('category', $request->file('category-image'));
First of all the recommended location for that stuff is to stay on the public path not creating a new one, unless there is an actual reason for that. Did you actually check that the symlink was created?
Laravel has an own command the create a symlink from storage/app/public to public/storage (the storage folder will be generated afterwards):
php artisan storage:link
But if you want to create defaults symlinks you should create one for yourself, like you already did.
This is the symlink pattern:
ln -s target source (fill in your target and source path)
So if you actually get the correct file from your request, this code should work:
Storage::putFile($name, $request->file('category-image'));
For more and detailed infos look into the filesystem documentation

Laravel download not working

In my application I have the need to:
upload a file
store information in the db
store the file in a local or remote filesystem
listing all the db rows with a link to download the file
remove the file from the db and from the filesystem
I am trying to develop the 4th but the solutions found here and here don't work for me.
My filesystem.php is:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
'myftpsite' => [
'driver' => 'ftp',
'host' => 'myhost',
'username' => 'ftpuser,
'password' => 'ftppwd',
// Optional FTP Settings...
// 'port' => 21,
'root' => '/WRK/FILE/TEST',
// 'passive' => true,
// 'ssl' => true,
// 'timeout' => 30,
],
In the Controller I store the file with:
... validation here ...
$path = $request->uploadfile->storeAs('', $request->uploadfile->getClientOriginalName(), self::STORAGEDISK);
$file = new TESTFile;
... db code here ...
$file->save();
At this point I would like to retrive the variable to pass to the download methods (url or path of my file). I found 2 ways
Storage::url($pspfile->filename) *return* **/storage/** accept.png
Storage::disk(self::STORAGEDISK)->getDriver()->getAdapter()->applyPathPrefix($pspfile->filename) *return* C:\xampp\htdocs\myLaravel\ **storage** \app\accept.png
Any help or suggestion to do it in a better way will be very appreciated.
EDIT
For the moment I separete local/public from FTP.
The download is working if in the Controller I modify
$path = $request->uploadfile->storeAs('',
$request->uploadfile->getClientOriginalName()
,self::STORAGEDISK);
$file->fullpath = $path;
with
$file->fullpath = storage_path('app\\') . $path;
where 'app\' is the storage_path configured as root in filesystem.php
Moreover I can avoid to hardcode and use
$file->fullpath = Storage::disk(self::STORAGEDISK)
->getDriver()
->getAdapter()
->getPathPrefix() . $path;
In this way the download method can use
return response()->download($pspfile->fullpath);
I am still looking for a way to retrive a valid scr attribute for an img tag.
In addition I would like the same with remote stored files (maybe with local temp dir and file?)
I made something similar some time ago. Maybe this example code helps you.
class FileController extends Controller
{
// ... other functions ...
public function download(File $file)
{
if (Storage::disk('public')->exists($file->path)) {
return response()->download(public_path('storage/' . $file->path), $file->name);
} else {
return back();
}
}
public function upload()
{
$this->validate(request(), [
'file-upload' => 'required|file',
]);
$path = request()->file('file-upload')->store('uploads', 'public');
$file = new File;
$file->name = request()->file('file-upload')->getClientOriginalName();
$file->path = $path;
$file->save();
return back();
}
}

Resources