Hi I do not know what is happening but I want to get a file from the storage folder and it says that it does not existe but it exists I mean I go to the folder and it is there..
I retrieve the file like this:
$path = storage_path('app/public/' . $settlement->support);
$settlement_file = Storage::disk('local')->get($path);
And I get this error:
message: "File not found at path:
home/jysparki/newjis.jisparking.com/storage/app/public/06152617_8-2025.pdf"
and If I go to the folder it exists so I wonder what am I doing wrong? Thanks.
If you look at config/filesystems.php file and find disks array, you may notice that root under the local disk key is set to storage_path('app'). Well it's up to what the value may be in your case you're free to change it, but what does this mean is whenever you call Storage::disk('local') method it will try to find files relative to storage_path('app'), so there is no need to specify full path. Try this instead
$settlement_file = Storage::disk('local')->get('/public/' . $settlement->support);
or
$settlement_file = Storage::disk('public')->get($settlement->support);
as Laravel by default has public disk which pointed into /app/public storage directory
Related
So, I've already dug through the questions here about this, but still can't seem to figure it out.
Do you know what I am doing wrong here?
$imageName = $thishire->color_image;
$path = public_path('/img/colorImages/' . $imageName);
$file = Storage::get(public_path('/img/colorImages/'. $imageName));
$file->move($path, public_path('/img/uploads'));
The 3rd line is throwing an error:
"File not found at path: Applications/MAMP/htdocs/GT Laravel/public/img/colorImages/l18Ow1uVBqhReGqW7lWjanp2vT5bOAKt8pylnmmb.jpg"
But that is the correct path, so I'm super confused.
You shouldn't do Storage::get(public_path('/img/colorImages/'. $imageName)).
Storage::get() is relative to the storage disk root.
If you use the default storage configuration, then your storage root path is storage_path('app'), said otherwise /path/to/your/project/storage/app.
This is what's happening:
Storage::get(public_path('/img/colorImages/'. $imageName));
// looking into /path/to/your/project/storage/app/path/to/your/project/public/img/colorImages
// which is obviously wrong
What you should do instead:
Store your public files in the storage/app/public directory
Use the php artisan storage:link command to create a symlink between public and storage/app/public. If you are not familiar with this concept, it'll create a small file into your public directory which is a shortcut to the storage/app/public directory. More about this here: https://laravel.com/docs/8.x/filesystem#the-public-disk
For instance, with a file named helloworld.jpg and located in storage/app/public/users/8/helloworld.jpg, you can get it by doing:
Storage::disk('public')->get('users/8/helloworld.jpg');
// or Storage::get('public/users/8/helloworld.jpg');
I know it can be confusing at first. This is a quick tip to "know where you are and what your are looking at". Use Storage::path():
dd(Storage::path(public_path('/img/colorImages/'. $imageName)));
// you'll see the problem
don't forget public meaning access storage but by created symlink
I think you should be store image in your path before getting it by using
Storage::put(public_path('/img/colorImages/'), $imageName);
and you can check documentation from here
I solved it.
$imageName = $thishire->color_image;
$old = public_path('/img/colorImages/'.$imageName);
$new = public_path('/img/uploads/'.$imageName);
rename($old, $new);
i'm having troble deleting a file from a Laravel Project.
The file is in the /storage/exports directory, it's an excel stored on the disk usingthe Laravel Excel library.
This is my code:
$path = $excel->store('xls', false, true)['full'];
...send the xls via mail....
Storage::delete($path);
When i check the existence of the file with file_exist i get true, so Laravel is able to read the file.
I've also checked the permission for the folder and i give all permissions on this folder using chmod 777
Any ideas?
Thanks!
The storage driver already has an awareness of a root directory, so the $path must be relative, not full. So if your file is in:
/this/is/the/full/path.xls, and the config filesystems.disks.local.root is set to /this/is/the/full, you're essentially having it look for a file in /this/is/the/full/this/is/the/full/path.xls.
You have two options.
1) Add a new driver to that config, and reference it directly:
'custom_location' => [
'driver' => 'local',
'root' => '/some/other/root/path',
]
Storage::driver('custom_location')->delete($relativePathFromRoot)
2) Create a one-off:
$rootPath = '/some/other/root/path';
$client = Storage::createLocalDriver(['root' => $rootPath]);
$client->delete($relativePathFromRoot);
Try storing the file within storage/app/exports. The Storage class's default location to store files is storage/app.
It may be a good idea to instead of using the Excel class to store the file, to instead save the file using the Storage class: Storage::put('exports/excelfile.xls', $fileContents);
Even though you are using Laravel, you can use regular PHP functions.
unlink($path);
I am using laravel/lumen. I am able to save files using Storage::disk("local")->put(); in my storage directory. However now I want to attach a few of those files to an email and send, this is done with a job the error I get is
lumen.ERROR: exception 'Swift_IoException' with message 'Unable to
open file for reading
Now I read something about symbolic linking which I tried but that simply did not change the result, I was still unable to attach files i n my storage folder to my emails.
This is my directory structure:
/home/xxxxxx/:
-example.app
--storage
---app
----public
-public_html
--example.app
---storage
Attaching the file like this:
foreach ($params["attachments"] as $attachment) {
$mail->attach($attachment["file"], [
'as' => $attachment["name"],
'mime' => $attachment["mime"]
]);
}
You've already realized that attach() method expects the full path to the file. However, others may find useful know how to achieve that. So, in case you're using the default settings for local store, you may be able to get the full path by calling the storage_path() helper. This way:
/*
* This will return the full path to the file:
*
* /path/to/laravel/storage/app/attachment/path
*/
storage_path('app/' . $attachment['file']);
Okay so apparently swift mailer fails when you pass a full url instead of the real path to the file. Didn't know this, don't know if it's a bug or it was done by design.
error log
Notice: Use of undefined constant tmp - assumed 'tmp' in /home3/dishapub/public_html/includes/src/__default.php on line 60532
In line 60532 line - return new $backendClass($backendOptions);
does anyone can provide soluion?
Thanks in advance
It sounds like you've not got permissions to write to your tmp folder.
Look in /lib/Zend/Cache/Backend.php and you'll see a method called getTmpDir(), that loops through all the places that Magento thinks your temp folder could exists.
Usually the folder is named "tmp" and is on the root, so check if it's there and that it has read and write permissions, if it's not, then you'll have to find where your temp folder is and if it's in the method list, and if it has read/write permissions.
I upload the files alright. Only it turns out that, in my case, the starting directory is Public, and that results that the files are accesible by everybody when they should be in the directories that are protected by previous authentication, that is, under App.
So, when I do this:
$file = Input::file('fichero');
$destinationPath = 'uploads/folder';
$file->move($destinationPath);
// Create model
$model = new Model;
$model->filename = $file->getClientOriginalName();
$model->destinationPath = $destinationPath;
The file is saved in here: localh.../myweb/public/
and that is outside the App parent folder where all my application files are.
I can imagine that the fact that is going to that directory is because it is taking the default in the configuration file, which is localhost/laravel/public/index.php/
so, writing something like
$file->move(base_path().'/uploadfolder/subdirectory/', $newname);
will start from what is fixed as base_path, but the base_path needs to be something like localhost/mywebname/public.
So, how do you write the path so that it goes to directories under App and not under Public?
I hope I am not asking a dumb question, but I have been trying for days and I have read the 3 related queries in here.
thank you
You may use:
app_path() // Path to the 'app' folder
app_path('controllers/admin') // Path to the 'app/controllers/admin' folder
This will return you local file system path, you should put your uploaded images in public/... folder.