我已经添加了一个管理菜单标签,可以通过Wordpress后端上传文件。我打算调整我在http://php.net/manual/en/function.ftp-put.php
找到的一些PHP代码唯一的问题......我甚至无法让它按原样运作。它连接到ftp服务器,但文件上传总是失败。我尝试了很多变化。有什么想法吗?
add_action( 'admin_menu', 'ftp_menu' );
function ftp_menu() {
add_menu_page( 'FTP Options', 'FTP', 'manage_options', 'ftp-options', 'ftp_options' );
}
function ftp_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
if(isset($_POST['ftp']))
{
$ftp = $_POST['ftp'];
$username = $_POST['username'];
$pwd = $_POST['pwd'];
$filename = $_FILES['file']['name'];
$tmp = $_FILES['file']['tmp_name'];
$d = $_POST['des'];
$connect = ftp_connect($ftp)or die("Unable to connect to host");
ftp_login($connect,$username,$pwd)or die("Authorization Failed");
echo "Connected!<br/>";
if(!$filename)
{
echo "Please select a file";
}
else
{
ftp_put($connect,$filename,$tmp,FTP_BINARY)or die("Unable to upload");
echo"File successfully uploaded to FTP";
}
}
?>
<div class="main">
<h1>FTP</h1>
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="ftp" placeholder="FTP link"/><br/>
<input type="text" name="username" placeholder="Username"/><br/>
<input type="password" name="pwd" placeholder="Password"/><br/>
<input type="file" name="file" /><br/>
<input type="text" name="des" placeholder="Destination" /><br/>
<br/><input type="submit" value="Upload"/>
</form>
</div>
<?php
}
最终,我希望能够只点击一个按钮并将我的网站上的csv文件上传到远程FTP目录。 (因此源文件将是一个完整的URL,目标是一个ftp文件夹。)感谢您的帮助!