Laravel 4 can not upload image - laravel

I use Laravel 4.2 on wamp server.
Error:
Intervention \ Image \ Exception \ NotWritableException Can't write
image data to path (C:\wamp\www\laravel.....)
my script:
$image = Input::file('image');
$filename = date('Y-m-d-H:i:s').".".$image->getClientOriginalExtension();
$path = public_path('img/products/' . $filename);
Image::make($image->getRealPath())->resize(468, 249)->save($path);

You must enable FileInfo extension and PHP >= 5.3 (preferably 5.4) and GD or Imagick extensions for image manipulations

Related

Laravel 9 Digitalocean spaces upload file

$filename = time() . $file->getClientOriginalName();
Storage::disk('do')->put("public/images/{$directory}/{$filename}", File::get($file), 'public');
return "images/avatars/{$filename}";
I upload file there is not any error but file doesn't upload to digitalocean spaces

How to run Artisan command without a console

Someone know how to start command without console
Let me explain
After the file is downloaded successfully, you need to run the command php artisan db:seed
I tried this option but I got an error as a result
Maybe someone knows another solution to this problem
I will be very grateful
I tried this option but I got an error as a result
$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
return redirect()->route('admin.accounts');
I tried this option
$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
return redirect()->route('admin.accounts');
Artisan::call('db:seed');
And this
$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
return redirect()->route('admin.accounts')->with(Artisan::call('db:seed'));
I think this option might work. but put artisan call above return. any lines of code after return will be ignored.
$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
Artisan::call('db:seed');// <---- this line
return redirect()->route('admin.accounts');

Unable to upload video file

I am trying to upload a video file with my controller as below
Controller
if(Request::hasFile('file1')){
echo "Yes, file";
exit;
$file = Request::file('file1');
$filename = $file->getClientOriginalName();
$path = public_path().'/uploads/';
return $file->move($path, $filename);
} else {
echo "No file";
exit;
}
When i submit my a JPG/PNG file, it echo "Yes, file" i.e the file exist but when i submit an MP4 video, the file isn't found..
What could be the issue please ? Is there a particular way of sending Mp4 to my server in Laravel ?
The issue here can be your php configuration in php.ini regarding the max allowed size of the uploaded file.
post_max_size
upload_max_filesize

Symfony command finding folder

I am trying to call command using symfony Process and command looks like:
$data = escapeshellarg("public\uploads\post_data.txt");
$url = "www.example.com/";
$process = new Process(['ab -n 10 -p '.$data.' -T application/x-www-form-urlencoded -w '. $url . 'test/send']);
$process->run();
When i call this command from terminal it works fine but when i try to call it using symfony command then i am getting:
The filename, directory name, or volume label syntax is incorrect. This error is windows terminal error as i know and i think the problem is with \ but i have tried to change it to \\, // and / but not helped.
In my point of view, your approach doesnt work, because new Process needs to be defined in a array, where each piece of the shellcmd is a entry in the array.
So for your case, you should have to write
$process = new Process(['ab', '-n', 10, '-p', $data, '-T', 'application/x-www-form-urlencoded', '-w', $url.'test/send']);
Or try with the fromShellCommandline static function
$process = Process::fromShellCommandline('ab -n 10 -p '.$data.' -T application/x-www-form-urlencoded -w '. $url . 'test/send');

How to get duration a video - laravel

I want to get the duration of my videos when I upload them.
To do this, I upload my videos like this:
$video = Carbon::now()->timestamp . '_' .
$request->file('video')->getClientOriginalName();
$request->file('video')->move(
$this->getCorrectPathOnServerAndLocal('/assets/videos/videos'), $video
);
My movie is uploaded well.
now I want to get the duration of this video.
I'm using PHP-FFMpeg:
composer require php-ffmpeg/php-ffmpeg
$ffprobe = FFProbe::create(); //error
dd("test");
$duration = $ffprobe
->format($this->getCorrectPathOnServerAndLocal('/assets/videos/videos').$video) // extracts file informations
->get('duration');
but I got this error:
(2/2) ExecutableNotFoundException
Unable to load FFProbe
in FFProbeDriver.php (line 50)
at FFProbeDriver::create(array(), null)in FFProbe.php (line 207)
first install getID3 by composer require james-heinrich/getid3
then
$getID3 = new \getID3;
$file = $getID3->analyze($video_path);
$duration = date('H:i:s.v', $file['playtime_seconds']);
I personally created a Video CMS and found the easiest way to be using ID3 as follows:
public function getDuration($full_video_path)
{
$getID3 = new \getID3;
$file = $getID3->analyze($full_video_path);
$playtime_seconds = $file['playtime_seconds'];
$duration = date('H:i:s.v', $playtime_seconds);
return $duration;
}
Before I used ffmpeg like this:
// Get the video duration
$parameters = "2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//";
$cmd_duration_ffmpeg = "$ffmpeg_path -i $full_video_path $parameters";
$duration = shell_exec($cmd_duration_ffmpeg);
Both options will work perfectly, choose whichever works best for you.
Using FFMPEG PHP library, and using FFprobe like this to get video duration in seconds:
$ffprobe = FFProbe::create();
$duration = $ffprobe->format($request->file('video'))->get('duration');
$duration = explode(".", $duration)[0];

Resources