[英]PHP script to upload all files and folders to FTP server
I have a problem and i cant figure it out. 我有一个问题,我无法解决。 I have a folder in local server that i want to upload it via FTP to a remote server.
我在本地服务器上有一个文件夹,我想通过FTP将其上传到远程服务器。 When i run the script in XAMP-apache in Windows i can upload it with no problems the subfloders and all files, now i try to use the same PHP script for the same folder to the same destination from linux apache but i get "file not found, please try again" Any help will be much appreciated.
当我在Windows的XAMP-apache中运行脚本时,我可以毫无问题地上传子脚本和所有文件,现在我尝试将相同的PHP脚本用于linux apache中的同一文件夹到相同的目标,但是我得到的是“文件不找到,请重试”。我们将不胜感激。 Thank you!
谢谢!
<?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>';
?>
>
You've got a lot of backslashes in there. 你那里有很多反斜杠。 Are you using backslashes as your directory separator?
您是否使用反斜杠作为目录分隔符? That won't work on Linux.
那在Linux上不起作用。 You either have to use
/
or DIRECTORY_SEPARATOR
. 您必须使用
/
或DIRECTORY_SEPARATOR
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.