开发者

ZipArchive php class extract files as root. Why?

I have a php script:

$extract_dir = "./";
$extract_file = "extractME.zip";

$zip = new ZipArchive;
$res = $zip->open($extract_file);
if ($res === TRUE) {
    $zip->extractTo($extract_dir);
    $zip->close();
    echo "ok";
} else {
    echo "failed";
}

But when I execute this script, via http://www.mywebsite.com/extract.php

All the files on FTP are show with OWNER 'root', but not the user ex . 'neo' as it should be. So the user cant edit/rename/delete these files.

Is it possible to fix this anyhow (I own the server), that files w开发者_如何学Goill be extracted with 'USERNAME' OWNERSHIP ?


ozzwanted, for some reason your web server (apache) is running as root so any file it makes will be made as root. This should never be the case. apache usually runs as 'www-data' or 'httpd', or 'nobody' or 'god' depending on the linux distro.

I suggest you look into this from a sysadmin point of view and have someone sort it out for you before you end up getting exploited. (assuming this is a live server)

You can use www.php.net/chown function or your can run a 'chown' command on the command line or do it from PHP with something like system() or exec() functions.

Good luck.


It extract as the user running the webserver (note: you should not be running it as root). Try using chown.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜