使用PHP

时间:2016-05-26 11:49:06

标签: php windows permissions plesk

这里有一点具体问题。我正在开发PHP中的自动脚本,以便在客户想要进行演示站点设置时帮助创建演示Web应用程序。

我正在使用运行Plesk的专用服务器。

我的目的是创建一个新的子域,创建一个新的数据库,从其他地方复制数据库,从另一个文件夹复制站点文件,最后用他们的登录凭证给客户发电子邮件等。

我使用Plesk API RPC来创建完全正常工作的子域,数据库和数据库用户。我有数据库从其他地方复制模式,我有电子邮件部分工作。唯一可以解决我的问题是将文件从一个文件夹复制到另一个文件夹。

源文件夹属于同一个httpdocs'文件夹作为目标文件夹。我遇到的最初问题是open_basedir问题,我已经纠正了,但现在我已经得到了许可被拒绝的问题。

我知道我不能用Windows进行chmod。 我尝试通过exec()使用xcopy返回

string(13) "Access denied"

我也试过cacls和icacls,这两个都给我一个类似的错误

string(57) "Successfully processed 0 files; Failed processing 1 files"

没有给整个httpdocs文件夹写权限,我对如何进一步解决这个问题感到有点失落。任何建议/帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

这个脚本适用于我:

<?php

echo(system('xcopy /Y /Z "C:\Inetpub\vhosts\example.tld\httpdocs\index.html" "C:\Inetpub\vhosts\example.tld\httpdocs\index2.html"'));

您可以使用xcopy:

C:\Inetpub\vhosts\example.tld\httpdocs>xcopy index.html index5.html
Does index5.html specify a file name
or directory name on the target
(F = file, D = directory)? F
C:index.html
1 File(s) copied

但并非在所有情况下:

C:\Inetpub\vhosts\example.tld\httpdocs>xcopy /O index.html index4.html
Does index4.html specify a file name
or directory name on the target
(F = file, D = directory)? F
Access denied
0 File(s) copied

你也可以使用icacls:

C:\Inetpub\vhosts\example.tld\httpdocs>icacls index3.html /grant ftp3:(F)
processed file: index3.html
Successfully processed 1 files; Failed processing 0 files

你甚至可以禁用遗产:

C:\Inetpub\vhosts\example.tld\httpdocs>icacls index4.html /inheritance:r
processed file: index4.html
Successfully processed 1 files; Failed processing 0 files

答案 1 :(得分:1)

我设法使用以下代码解决了我的困境;

    system('icacls "C:\Inetpub\vhosts\domain.ltd\httpdocs\destination_subdomain" /grant:r "USER_USERNAME":(OI)(CI)F');
    system('xcopy /y /z /e "C:\Inetpub\vhosts\domain.ltd\httpdocs\source_subdomain" "C:\Inetpub\vhosts\domain.ltd\httpdocs\destination_subdomain\"');
    system('icacls "C:\Inetpub\vhosts\domain.ltd\httpdocs\destination_subdomain" /grant:r "USER_USERNAME":(OI)(CI)RX');

第一行为目标文件夹上的所选用户名设置完全权限。

第二行使用xcopy复制所有文件夹和子文件夹,甚至是从源文件夹到目标文件夹的空文件夹。

第三行将目标文件夹的权限重置为仅读取和执行。