I have a case suppose I upload an image for a product to a temporary directory called "uploads" and then later move it to another one called "products" and the image will be in a sub-directory which created dynamically like this
products/1/variants/1/image.jpeg
- "products" is the main directory have permission 0755 which is accessible
- "/1/variants/1/" dynamically created directory have permission 0700 which is not accessible and can’t read the image
my code of moving
$sourcePath = 'public/'.$image['path'];
$destinationPath = "products/".$product>id."/variants/".$variantImages['variantId']."/".pathinfo($sourcePath, PATHINFO_BASENAME);
Storage::makeDirectory("public/images/products/".$product->id."/variants/".$variantImages['variantId']);
Storage::move($sourcePath, "public/images/".$destinationPath);
notice : I use Hostinger hosting
image moved to the right directory but i can’t read because of the permission
I expect to read the image
- storage:link (symbolic link) is correct
- filesystem config for storage disk is correct and set to 0755
- I also tried to use storage visibility
Storage::setVisibility()
- when using Storage::makeDirectory($dir, 0755, true)
2
Answers
I think what you are trying to do is move images from the storage path to the public folder.
I think this is more the approach you should go. Either that or change the visibility if you want it persisted.
the public folder being accessible and then you can add the path you would like it to be found in. Same goes for the put.
if not and you are truly wanting to do what you are doing above and fix it. You have an error in question where you have "$product>id" and it should be "$product->id"
You have to check your user/group of your webserver, hopefully you have access to
ssh
and make necessary change.now you should be able to read the created image.