how to set permission 777 to a zip file?

2019-09-09 16:22发布

I am trying to zip files and I want to set the permission to chmod 777. But i don't know how/where I should write the chmod 777. Could anyone please help me? This is my code for zipping files.

$files = array(
            'download.xml',
            'script_.xml',

        );

        $zip = new ZipArchive();
        $zip_name = "testabc.package";
        if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){
            $error .= "* Sorry ZIP creation failed at this time";
        }

        foreach($files as $file){
            $zip->addFile($file);
        }

        $zip->close();
        echo shell_exec("zip -P pass test.zip script.xml");

标签: php zip chmod
2条回答
smile是对你的礼貌
2楼-- · 2019-09-09 16:39

It's possible you do not have the required permission to change file permissions. I would suggest contacting your hosting provider to have them change it for you. Generally, 777 is a very bad permission to have set on any file. See: https://webmasters.stackexchange.com/questions/18280/why-chmod-777-is-not-secure

If you do own the machine, run sudo chmod 777 filename.zip

查看更多
Bombasti
3楼-- · 2019-09-09 16:45

add this to your code.

chmod("/to/your/zip/file", 777);

And for more informations read php manual for chmod

查看更多
登录 后发表回答