[英]PHP script to upload all files and folders to FTP server
我有一個問題,我無法解決。 我在本地服務器上有一個文件夾,我想通過FTP將其上傳到遠程服務器。 當我在Windows的XAMP-apache中運行腳本時,我可以毫無問題地上傳子腳本和所有文件,現在我嘗試將相同的PHP腳本用於linux apache中的同一文件夾到相同的目標,但是我得到的是“文件不找到,請重試”。我們將不勝感激。 謝謝!
<?php
ob_start();
set_time_limit(0);
$sourcedir="source_folder"; //this is the folder that you want to upload with all subfolder and files of it.
$ftpserver="192.168.1.150"; //ftp domain name
$ftpusername="user"; //ftp user name
$ftppass="user"; //ftp passowrd
$ftpremotedir="destination_folder"; //ftp main folder
$ftpconnect = ftp_connect($ftpserver);
$ftplogin = ftp_login($ftpconnect, $ftpusername, $ftppass);
if((!$ftpconnect) || (!$ftplogin))
{
echo "cant connect!";
die();
}
function direction($dirname)
{
global $from,$fulldest,$ftpremotedir,$ftpconnect,$ftpremotedir;
chdir($dirname."\\");
$directory = opendir(".");
while($information=readdir($directory))
{
if ($information!='.' and $information!='..' and $information!="Thumbs.db")
{
$readinfo="$dirname\\$information";
$localfil=str_replace("".$from."\\","",$dirname)."";
$localfold="$localfil\\$information";
$ftpreplacer=str_replace(array("\\\\","\\"),array("/","/"),"$ftpremotedir\\".str_replace("".$fulldest."","",$dirname)."\\$information");
if(!is_dir($information))
{
$loading = ftp_put($ftpconnect, $ftpreplacer, $readinfo, FTP_BINARY);
if (!$loading)
{
echo "<font color=red>Files not found... Please try again...</font>"; echo "<br>"; fls();
}
else
{
echo "<font color=green> Please wait... Uploading files</font>"; echo "<br>"; fls();
}
}
else
{
ftp_mkdir($ftpconnect, $ftpreplacer);
direction("$dirname\\$information");
chdir($dirname."\\");
fls();
}
}
}
closedir ($directory);
}
function fls()
{
ob_end_flush();
ob_flush();
flush();
ob_start();
}
$from=getcwd();
$fulldest=$from."\\$sourcedir";
direction($fulldest);
ftp_close($ftpconnect);
echo '<font color=red>Your folder is now ready for use <font color=red>';
?>
>
你那里有很多反斜杠。 您是否使用反斜杠作為目錄分隔符? 那在Linux上不起作用。 您必須使用/
或DIRECTORY_SEPARATOR
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.