簡體   English   中英

使用PHP在Windows服務器上復制文件

[英]Copy files on windows server using PHP

這里有一個特定的問題。 我正在用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文件夾寫權限,我對如何最好地進一步解決這個問題感到有點茫然。 任何建議/幫助將不勝感激。

該腳本適合我:

<?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

我使用下面的代碼設法解決了我的困境;

    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復制所有文件夾和子文件夾,甚至將空文件夾從源文件夾復制到目標文件夾。

第三行將目標文件夾的權限重置為只讀和執行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM