chmod(): Operation not permitted when upload file with laravel 6 - php

I am using file system storage to upload files. When I change filesystem_driver from local to public I get this error :
vendor/league/flysystem/src/Adapter/Local.php:367
public function setVisibility($path, $visibility){
$location = $this->applyPathPrefix($path);
$type = is_dir($location) ? 'dir' : 'file';
$success = chmod($location, $this->permissionMap[$type][$visibility]); // line 367
if ($success === false) {
return false;
}
Disk settings
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'permissions' => [
'file' => [
'public' => 0664,
'private' => 0600,
],
'dir' => [
'public' => 0775,
'private' => 0700,
],
],
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
I tried to change the file permissions according to this post, but it doesn't work. If I change the filesystem_driver to local I cannot display the pictures in front end. This is a local development environment WSL Ubuntu 18.
What do I do wrong here?

problem was cmod is not support under ntfs file system https://github.com/Microsoft/WSL/issues/81

Related

Laravel 9 With Image Intevention: Can't write image data to path

I have a Laravel 9 Forum project and I want to make a upload system manager with Image Intervention package (each uploaded image will be resized into the pre-defined custom sizes).
So I made a table named uploaded_files and it's migrations goes like this:
Schema::create('uploaded_files', function (Blueprint $table) {
$table->id();
$table->bigInteger('upf_object_id');
$table->unsignedBigInteger('upf_object_type_id')->nullable();
$table->string('upf_path');
$table->string('upf_uploaded_as');
$table->string('upf_dimension',15);
$table->string('upf_option')->nullable();
$table->string('upf_type',50);
$table->string('upf_category');
$table->string('upf_mime_type');
$table->string('upf_relation_type',40)->nullable();
$table->string('upf_file_name')->nullable();
$table->string('upf_file_hash')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreign('upf_object_type_id')->references('id')->on('baseinfos')->onDelete('cascade');
});
Now for uploading images, I put this code at the Controller:
if($request->has('filep')){
$files = $request->file('filep');
foreach ($files as $file) {
$this->uploadImage($file, $questionCreated->id, 'question_image');
}
}
So if the request has an uploaded file, the method uploadImage will be called:
public function uploadImage($request, $id, $type_image)
{
$imagesUrl = UploadFile::upload($request,"Question",$id);
foreach ($imagesUrl['path'] as $path) {
UploadedFile::create([
'upf_object_id' => $id,
'upf_object_type_id' => $this->objectTable('questions'),
'upf_path' => $path['upf_path'],
'upf_uploaded_as' => $type_image,
'upf_dimension' => $path['upf_dimension'],
'upf_type' => $imagesUrl['option']['upf_type'],
'upf_category' => $imagesUrl['option']['upf_category'],
'upf_mime_type' => $imagesUrl['option']['upf_mime_type'],
]);
}
}
And as you can see I have called here a Helper Class which is UploadFile and goes here.
But now the problem is whenever I test this, I get this error:
Can't write image data to path (C:\xampp\htdocs\laravel9project\storage\upload/1401/11/images/questions/51)
Which is referring to the line 117 of the UploadFile class:
->save(storage_path($path));
And I really don't know why this error occurs...
I have also ran the command php artisan storage:link and these links already exists:
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('storage/dist') => storage_path('app/dist'),
public_path('storage/upload') => storage_path('app/upload'),
],
So what's going wrong here? How can I solve this issue?
I would really appreciate any idea or suggestion from you guys about this...
Thanks in advance.
And this is the disks config of filesystems.php (if you want to take a look at):
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
'dist' => [
'driver' => 'local',
'root' => storage_path('app/dist'),
'url' => env('APP_URL') . '/storage/app',
'visibility' => 'public',
'throw' => false,
],
'upload' => [
'driver' => 'local',
'root' => storage_path('app/upload'),
'url' => env('APP_URL') . '/storage/upload',
'visibility' => 'public',
'throw' => false,
],
],
Image Intervention version installed on my project:
"intervention/image": "^2.4",

Laravel 5.2 InvalidArgumentException in FilesystemManager.php line 121: Driver [] is not supported

Filesystem.php
I have some problem when I try to create a new disk in Laravel 5.2
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
'manifest' => [ // it´s works if only stay this
'driver' => 'local',
'root' => storage_path('../../manifestations_media'),
'visibility' => 'public',
],
'documentos' => [ // if add this nothing works
'driver' => 'local',
'root' => storage_path('../../documentos'),
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
],
],
I don't know why it fails, but if I try adding a new disk fails all configuration doesn't work. Can somebody help me understanding why, please?
$mytime = time();
$ext = pathinfo($request->myfile->getClientOriginalName(), PATHINFO_EXTENSION);
$filename = sha1_file($request->file('myfile')->getRealPath()) . $mytime . "." . $ext;
Storage::disk('documentos')->put($filename, file_get_contents($request->file('myfile')->getRealPath()));
DB::update('update cities set document = ? where id = ?', [$filename, $data]);
I solve my problem change the version Laravel 6. This mistake doesn´t. I dont known why happen In Laravel 5.2. It´s possible that i have changed something that i can´t remember, but for the moment it´s works

laravel file upload on a project on a hosted project

I have hosted my laravel application, before this file uploads and everything was working fine, but after I put it on cpanel, File uploading is nolonger working.
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
this is my code, may someone help. in my .env file I inserted my app url for the website which is working file except for file upload
Regards

Images doesn't save in the correct location in Laravel

I have an image upload form in my Laravel project.
I want to save the upload image into public/images/ location.
But image upload into public/app/images location.
From where this app coming !!
config/filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => public_path(''),
],
'public' => [
'driver' => 'local',
'root' => public_path(''),
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
],
],
controller
if($this->request->hasFile('photo'))
{
$image_url = $this->request->photo->store('/images/campaign/large');
$image = substr($image_url, strrpos($image_url, '/') + 1);
}
Where is the mistake ? Anybody help please?
Thanks in advance

laravel5 create custom disk for uploading photo

I'm using laravel 5.6 and i wanted to create my custom disk for uploading images
and i received this error
InvalidArgumentException Driver [] is not supported.
this is how i save file in controller
$cover = $request->file('cover_image');
$extension = $cover->getClientOriginalExtension();
Storage::disk('test')->put($cover->getFilename().'.'.$extension, File::get($cover));
this is my config/filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'test' => [
'driver' => 'local',
'root' => storage_path(),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public/asghar'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
the error occurred because my configuration was cached.
probably I accidentally used config:cache or sth similar.
the issue resolved by clearing the config cache using this command
php artisan config:clear

Categories