I am uploading a zip file which I then need to get extracted at the path with the same file name. So I have used the Chumper/Zipper and to achieve my task I have used the following code i.e.
$zipper->zip('storage/apps/'.$name)->extractTo('storage/apps/'.$name);
It throws an error Failed to create folders at zipper.php at 534, which states, i.e.,
`if (!$this->file->exists($dir) && !$this->file->makeDirectory($dir, 0755, true, true)) {
throw new \RuntimeException('Failed to create folders');`
I figured out that there must a permission issue, so I did
sudo chmod -R 755 /var/www/html/admin-panel/public/storage/apps/
Still got the same error, so I again tried the above command with 777 which is both read/write in the parent directory.
Still, the issue is not resolved.
Help will be appreciated. Thanx
Are your sure, you have created "apps" folder in the storage directory? Laravel generates the folder named "app" by default.
Related
I have three folders (userImages, productImages and clientImages) inside the images folder with the public folder in a Laravel(9.5.1) project. I am trying to upload images and move same into the productImages folder but it is not working. However, if I try with the userImages folder, it works and works only with that folder. I would be glad for any assistance from you. Thank you for your assistance in advance.
This is code:
if($request->hasFile('product_image')){
$image = $request->file('product_image');
$newImageName = uniqid().'-'.Str::slug($request->product).'.'.$image->getClientOriginalExtension();
$location = public_path('/images/productImages');
$image->move($location, $newImageName);
}else {
$newImageName = 'default_image.png';
}
The error message I get from the above line of code is:
The stream or file "/Applications/XAMPP/xamppfiles/htdocs/pos/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file
You need to be specific with the directory you want to allow the permission. Like below for your case.
sudo chmod -R 777 /Applications/XAMPP/xamppfiles/htdocs/pos/public/images/productImages
Please make 777 for storage folder permissions. Laravel tries to log the error to the log file. But storage folder permissions don't let it. Then you will see what is wrong with your code in the log file.
sudo chmod -R 777 storage
I am trying to make a directory when a new account is created.
The directory should be in my images folder and is used to better separate uploaded images.
//get the ID of the new account that was just created/inserted
$accountID = mysqli_insert_id($dbc);
//create a new directory path for that account
$directoryPath = "../images/" . $accountID;
// check if the directory exists
if (!is_dir($directoryPath)) {
//create the directory
mkdir($directoryPath, 0777); //breaking here
}
I had no problem getting this to work a few days ago, however when testing it today I am having problems.
I have included ini_set('display_errors', 'On'); in my page to see what error I am being thrown and it is a permission error.
Warning: mkdir(): Permission denied
The images folder has full read/write permissions for all users and groups as well as any parent folders so I don't understand how that would be an issue, that and it had worked several times before.
I am working on windows if that matters.
Any ideas?
To avoid spending too much time on permissions problems between the CLI user and the Apache user, an easy configuration is to use same user for both processes.
Get your user id and group by doing
$ id
uid=1000(my_user), gid=1000(my_group), ...
And then:
$ sudo service apache2 stop
$ sudo vi /etc/apache2/envvars
export APACHE_RUN_USER=my_user
export APACHE_RUN_GROUP=my_group
$ sudo chown -R my_user /var/lock/apache2
it's better and safer than to change you whole directory permission to 777
I think you should try this -
mkdir("../images/".$accountID, 0777, 'R');
Recursive folder creation may causing the problem.
Also get more information from - mkdir
Also check for folder permission.
You have to be sure that the parent directory allows you to create folder, and not the folder it self that is being created with 0777 rights...
Also, check with which user the Apache server is launched
Check if directory is already exist before using mkdir()
if (!is_dir ($directoryPath) ) {
mkdir($directoryPath, 0777);
}
I am working on windows if that matters.
It does.
Try changing this
if (!is_dir($directoryPath)) {
//create the directory
mkdir($directoryPath, 0777); //breaking here
}
To this
if (!is_dir($directoryPath)) {
//create the directory
mkdir($directoryPath); //breaking here
}
You are on a Windows box so it will ignore the chmod mode. Also try using the full paths and not relative.
The mode is 0777 by default, which means the widest possible access.
For more information on modes, read the details on the chmod() page.
Note:mode is ignored on Windows.
http://php.net/manual/en/function.mkdir.php
I have folder hierarchy as Bucharest/Waterfall/a.php. My code snippet for making directory on server is as follows:
if(!is_dir($this->folder)){
$old_umask = umask(0);
mkdir($this->folder, 0777);
umask($old_umask);
}
chmod($this->folder, 0777);
// Moves current file to upload destination
if(move_uploaded_file($current['tmp_name'],$uploadFile))
return true;
All files are uploaded to the server. Now the issue is that the parent folder ,i.e. Bucharest has permission 755 while inner folder has permission 777. $this->folder has value as Bucharest/Waterfall. It gives 755 permission to Bucharest while 777 permission to waterfall. According to my code the 777 permission should also be given to Bucharest.
I have also tried chmod but all in vain. I want to give full permission to parent folder.
is_dir($this->folder); tells you that the file isn't a directory, not that it doesn't exist. and of course you can't mkdir if the directory is already there.
Also, if the directory already exists, according to the documentation chmod will not do anything if the user under which php is running isn't the same as the user who owns that directory.
Is the folder you are checking a subfolder already? If so, create the parent folders firts.
i.e.
mkdir('/tmp/test1/test2/test3/test4');
will fail if '/tmp/test1/test2/test3' doesn't exist
I have my web application hosted in /var/www folder. I am creating a folder from one of the PHP scripts of the web application. The default permission of the created folder is drwx------, i.e. 700. But I want that folder to have at least 755 permission.
Up to now I tried: mkdir($path, 0755) and chmod($path, 0755) PHP functions but without any success.
Does anybody know how to solve my problem please?
Millions of thanks beforehand.
Have you tried changing the umask ?
Have a look here: http://nl3.php.net/manual/en/function.umask.php
The easiest way it to:
$oldmask = umask(0);
chmod($path, 0755);
umask($oldmask)
Since you have default permission of 700, which means the parent directory (the directory in which you are trying to create the folder) do not have rw permission for group owner or other users. Most often the running demon(httpd) is not the owner of the parent folder and hence cannot modify the directory.
In simple terms, the php script do not have access to modify or add new directory. You need to change the permission of the parent folder to at least drwxrw-rw- (or 0755).
Use ssh, cpanel or ftp client to do this. If you do it using php script you will end with the same problem again, as parent of parent will have again 0700. ;)
Hey I'm stuck with the following problem, plz help.
I get "Destination folder is not writable.." when trying to add an image to a product, but the permission for all needed folders is 777! I had deleted all files on server, didn`t touch DB, reinstalled Magento from scratch with new DB, and everything is OK.
But when I switched to previous DB (change settings in the local.xml) the bug appeared again.
How can the DB impact the folder permissions?
UPDATE:
Thanx a lot, we found out that Magento jump from this method:
public function getBaseMediaUrl()
{
return Mage::getBaseUrl('media') . 'catalog/product';
}
to the following method:
public function getBaseTmpMediaUrl()
{
return Mage::getBaseUrl('media') . 'tmp/catalog/product';
}
Does anybody know why and how????
There's only one spot in the Magento code base that uses that error language.
File: lib/Varien/File/Uploader.php
...
if( !is_writable($destinationFolder) ) {
throw new Exception('Destination folder is not writable or does not exists.');
}
...
Add some temporary debugging code right above this
...
if( !is_writable($destinationFolder) ) {
Mage::Log($destinationFolder);
//or
var_dump($destinationFolder);
throw new Exception('Destination folder is not writable or does not exists.');
}
...
This will let you know the exact folder Magento wants to write to, but can't. Examine this folder, and you'll find it's not writable. Reviewing the edge cases on is_writable may also shed some light on the subject.
Goto : lib/Varien/File/Uploader.php
Temporary change the following code and try to upload image. Now in error message you can see folder path.
In folder path you have to give file permission 777 and it will work as normal. After the error is resolved revert your code to as it wass.
if( !is_writable($destinationFolder) ) {
var_dump($destinationFolder);
throw new Exception(''.$destinationFolder.'Destination folder is not writable or does not exists.');
}
I got the below error while uploading images in Magento then I did the below steps and that worked for me.
Cd /var/www/
chmod 755 -R /html
chown apache:apache -R /html
setenforce 0
then restart apache ..
Magento 2
This is the file in Magento 2 where the error come from:
vendor/magento/framework/File/Uploader.php
At line 256 you can temporarily place this code to get the unwritable/unexisting folder:
if( !is_writable($destinationFolder) ) {
error_log($destinationFolder);
// or
// throw new Exception('Destination folder is not writable or does not exists.');
throw new Exception($destinationFolder);
}
Otherwise you can check you have these folders and that are writable by the web server:
pub/media/catalog/
pub/media/catalog/category
pub/media/catalog/product
pub/media/images
pub/media/wysiwyg/
It may be the expired certificate from the Plesk administration (it was my case).
I tried the steps above, but it did not work. From there I tried to access the files through FileZilla to give the permissions at once to all folders, hence an error message about the expired certificate. It is not the SSL certificate of the store itself, but the administration of Plesk. I created a new self-signed certificate, applied its Plesk administration and everything went back to normal.
This worked for me. I leave here my contribution.
Good luck
I had the same problem:
Sign in to your SSH:
Give media folder permissions through run this command:
cd public_html/media
find . -type d -exec chmod 777 {} \;
My issue is solved after changing the permissions of the media folder. Just go locate the media folder on your server, right click->change permissions->set value 777 for folder permissions.