rmdir permission denied on mac - php

I'm running the following PHP in a virtual server on my mac:
$dir = './setup/';
$files = glob($dir.'*',GLOB_MARK);
foreach($files as $file) { unlink($file); }
rmdir($dir);
It's meant to delete all files in a directory called setup then delete the setup directory.
It deletes the files fine, but then throws the following error:
Warning: rmdir(./setup/) [function.rmdir]: Permission denied
I have read and write permissions set on the setup directory for everyone. What else can I do to get this to work?

I think this will do the trick:
Open Terminal on your Mac
Type "chmod 777 [path]" and press Enter. Change [path] to the location of the folder you are trying to delete, for example /var/www/folder, like "chmod 777 /var/www/folder"
Now you should be able to delete the folder.

Related

move_uploaded_file Failed to open stream: Permission denied in XAMPP MacOS

I was trying to upload a file using php to my local using XAMPP on MacOS. Whenever I tried to upload a file through script, I got thi error.
move_uploaded_file - Failed to open stream: Permission denied
So I tried some fixes I saw on internet, like chmod -R 777 , changing the user-group and also tried to give read&write permission to every user;
None of them worked.
This is the code I am using for uploading:
if(!empty($filename)){
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$new_filename = $slug.'_'.time().'.'.$ext;
if(!move_uploaded_file($_FILES['eventImage']['tmp_name'], '../assets/images/events/'.$new_filename))
{
$_SESSION['error']='<strong>Error!</strong> Uploading Image failed. Please try again.';
}
}
else{
$new_filename = '';
}
I wanna know how this error can be fixed. I think this is some security issues of MacOS.
like under nix, You can try (under test - not productive server):
chmod -R 755 ./.*
chmod +x ./.
where ./is your document root of HTML files (do not use it as root/admin !!!)
the Argument -R stands for "recursive operation" - so it will try to include all sub directories under ./
and:
chown -R www-data:www-data ./.
at Your document root.
www-data group, and user is need by Apache2.4 - see Settings in Manual.
The group, and user www-data is important under *nix like Operation Systems.
Under Windows, You have to start XAMPP with Administrator Rights.
So be warned !!!
And: You should never be use XAMPP productive !!!

Make a copy of a File with PHP or JavaScript

How can I make a copy of a file on my server from a site either in PHP or JavaScript?
I tried the following:
<?php
$file = 'example.txt';
$newfile = 'example.txt.bak';
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}
?>
But I keep getting the "failed to copy" message
I created a copy.php file in my var/www/html folder (Using Apache in Ubuntu) and I ran the copy.php file in my browser http://localhost/copy.php
My example.txt is sitting right in the same folder that copy.php
Thanks
You need to set destination folder permissions to 646. Use your domain cpanel or equivalent to do that
In ubuntu you would need to set your folder permissions so navigate to your project directory using cd in the command prompt 'cd /var/www/html/myproject'
var/www/html/myproject
Lets say the folder your want to copy to is located at
var/www/html/myproject/copied_files
now run the command 'sudo chown -R <your username on ubuntu>:www-data <folder name>
It should look like this
Lets say my user name is prince
prince#computer: var/www/html/myproject $ sudo chown -R prince:www-data copied_files
Essentially your giving the group "www-data" which is your server permission to write files to that directory while you still have ownership to it. The '-R' says that all subfolders should be writable by 'www-data' (your server) so you don't have to manually make it writeable and the 'copied_files' is the name of directory for your server to write too :)

move_uploaded_file failed to open stream: Permission denied - Mac

While i am trying to move_uploaded_file in php with following code :
if(is_uploaded_file($_FILES['fileupload2']['tmp_name'])){
move_uploaded_file($_FILES['fileupload2']['tmp_name'], "images/".$_FILES['fileupload2']['name']);
}
I've got this error saying:
Warning: move_uploaded_file(images/VIDEO_TS.VOB): failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/Week3/Lesson2/do_upload.php on line 24
i tried in the terminal and didn't work:
sudo CHMOD 775 /Applications/XAMPP/xamppfiles/htdocs/Week3/Lesson2/do_upload.php
sudo chmod -R 0755 /Applications/XAMPP/xamppfiles/htdocs/Week3/Lesson2/do_upload.php
sudo chown nobody /Applications/XAMPP/xamppfiles/htdocs/Week3/Lesson2/do_upload.php
I am still getting the error and i am using Yosemite, any other solution ?
My solution was to give the permission for the images folder and the php file, by going to the file > Right click > Get info > and then change all the permissions to read&write as the following picture.
I am using ubuntu and once I have encounter this problem, I have solved this problem by changing all the access permissions of the folder in which I want to move the files to 'create and delete files'. See below screenshot:
Set the same permission for your target(uploading) folder
This problem solved by changing permission as described avobe
and making the target folder in the same directory {Root rather than Home } in which application is running
path for image upload
/Applications/XAMPP/xamppfiles/htdocs/emp/files/admin_assets/addsdassets/targrt_Folder
path of folder in which application is running
/Applications/XAMPP/xamppfiles/htdocs/emp/files/admin_assets/addsdassets/inser_db.php
You can try after changing owner for the folder images where you are saving the images. It may work.
chown ownername:group folder;
you have to give absolute address of the folder
I was running Yii2 on IIS (Windows 10) and I tweaked the path and got it working. See code snippet below:
if($model->load(Yii::$app->request->post())) {
$image = UploadedFile::getInstance($model, 'image');
$model->image = $image->getBaseName().'.'.$image->extension;
if($model->save()) {
$image->saveAs('uploads/'.$model->image);//Notice the path change here
return $this->redirect(['view', 'id' => $model->ID]);
}
}
else {
return $this->render('update-image', [
'model' => $model
]);
}
Hope this helps.
This issue is caused by restricted permission. To resolve extend or change your permission to the folder using: chmod -R 777 folder-path.
E.g:
chmod -R 777 /opt/lampp/htdocs/php/aitech/images/passport_photos
apply
sudo chmod 777 images/
to the folder/directory which is your server folder to store images. Please check which is your folder. Totally depends on your choice.

Opencart fopen(/upload/system/logs/): failed to open stream: Is a directory

I got this error in my opencart shop right after uninstalling an extension. The complete shop does not work anymore. It has not my own template and all php functions do not work. This error shows up:
Warning: fopen(/my_path/system/logs/): failed to open stream: Is a directory in /my_path/system/library/log.php on line 6
This is the Log class:
class Log {
private $handle;
public function __construct($filename) {
//this is line 6
$this->handle = fopen(DIR_LOGS . $filename, 'a');
}
public function write($message) {
fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . print_r($message, true) . "\n");
}
public function __destruct() {
fclose($this->handle);
}
}
Looks like the $filename var is empty. This also reflects the not working php i mentioned above. The logs directory is 755 and i tried it with 777.
And a second error shows at the bottom of my shop:
Fatal error: Call to a member function get() on a non-object in /homepages/6/d421894284/htdocs/opencart/upload/index.php on line 104
Have anyone experienced this error in Opencart 2.0.1.1? Google says, that this must be a common error, but I canĀ“t find a solution.
the answer is simple , change ---->
define('DIR_STORAGE','/storage/');
define('DIR_STORAGE', DIR_SYSTEM . '/storage/');
and do that to config.php , and config.php inside admin folder , change both folders
this problem happens When the system cant create the storage folder which contains the logs cache and modification folders because of permissions problems ,some times the problem happens after storage directory transfer from the dash board , so to solve the problem you need to do the following
create a storage folder in the root of the application
sudo mkdir storage
set the new folder to 777 or 775 or 755 permissions sudo chmod -R 755 storage
create a storage folder in the root of the application
sudo mkdir logs
set the new folder to 777 or 775 or 755 permissions sudo chmod -R 755 logs
create a storage folder in the root of the application
sudo mkdir modification
set the new folder to 777 or 775 or 755 permissions sudo chmod -R 755 modification
The $filename for the log file is either not set in your admin panel or not being passed to the constructor. Check in Admin > System > Settings > Server > Error Log Filename and make sure you have something set there.
If so, next step would be to check the main index.php and make sure the code is intact around line 68 which should be :
$log = new Log($config->get('config_error_filename'));
$registry->set('log', $log);
$filename is empty , Find the filename because it not exist.
<?php
class Log {
private $handle;
public function __construct($filename) {
if (! empty( $filename )) {
$this->handle = fopen(DIR_LOGS . $filename, 'a');
}
}
public function write($message) {
fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . print_r($message, true) . "\n");
}
public function __destruct() {
fclose($this->handle);
}
}
check if $filename is not empty
We were facing the same problem and were able to resolve it by putting correct data in these two files:
config.php
admin/config.php
Please make sure that you have put correct entry for DB_PREFIX:
define('DB_PREFIX', 'oc_');
This is Local Project Root here, but you can change your Server Path easily.
Note: you can change to config.php and config.php inside admin folder both File Compulsory.
define('DIR_STORAGE', 'D:/xampp/htdocs/opencart_project/system/storage/');
OR
define('DIR_STORAGE', 'D:/xampp/htdocs/opencart_project/storage/');
chcon -R -t httpd_sys_rw_content_t /var/www/...
try this. i've solved this error using the command.
Is looking for the files inside your storage folder. Do this step by step
cd /var/www/opencart_storage/
mkdir logs
chmod 777 logs
cd logs
vim error.log
chmod 777 error.log
vim googleshopping.0.log
chmod 777 googleshopping.0.log
vim ocmod.log
chmod 777 ocmod.log
vim openbay.log
chmod 777 openbay.log
reload your opencart site
Presto!
I faced the same problem. Immediately after the installation appeared in the admin:
Warning: fopen (/ my_path / system / logs /): failed to open stream: Is a directory in /my_path/system/library/log.php on line 6
Here is the solution:
Permissions on the folder with logs after installation, you can leave 755! The file is located at /var/www/my_account/data/www/mysite.com/system/logs/openbay.log need to put permission 777. After that, I left all the mistakes.

How do I change chmod settings to allow for file upload?

I've been trying to get get my PHP script to upload files. However, I come across this error:
Warning: move_uploaded_file(images/faceBackground.png) [function.move-uploaded-file]: failed to open stream: Permission denied in /f5/mvcsf/public/portfolios/members_profile_chg.php on line 31
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/f5/mvcsf/tmp/phpjY9EBB' to 'images/faceBackground.png' in /f5/mvcsf/public/portfolios/members_profile_chg.php on line 31
After scouring multiple solutions on Stackoverflow, I got the hint that I should change the chmod settings. So I went into Filezilla and tried to change the file permissions for members_profile_chg.php(which contains the upload script) to 0755 and then to 0644, but neither worked. Any ideas? I'm using nearlyfreespeech as my web server if that makes any difference.
chmod 0777 the images folder instead of files.
Make sure your images directory is accessible and writeable (rwx) for the server user (probably apache).
~$ chmod g+rwx,o+rwx images/
Note that this makes the directory world-writable. Better is to only give the server user access (assuming it is apache):
~$ chown apache images/
~$ chmod g+rwx,o+rx images/
More information can be found here.
The numerical values you want to try are 0775 or 0777.
give permission to target folder folder in which permission 0755 or 0777 will work .also make sure that there is a folder named 'images' in the 'portfolios'
if the images is on the root try
move_uploaded_file("/images/faceBackground.png")

Categories