服务器 centos
1.安装 vsftpd (百度有好多文件介绍,这里就不介绍了)
2.index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="./index.php" method="post" enctype="multipart/form-data">
<input type="file" name="img">
<input type="submit" value="提交">
</form>
</body>
</html>
3.index.php
<?php
$ftpService = '图片服务器IP';
$ftpUserName = '图片服务器帐号(最好不要用root)';
$ftpPwd = '图片服务器密码';
$extension = pathinfo($_FILES['img']['name']);
$connect = ftp_connect($ftpService) or die('no service');
$loginf = ftp_login($connect, $ftpUserName, $ftpPwd);
$newFileName = "image".date('YmdHis').'.'.$extension['extension'];
ftp_put($connect,$newFileName,$_FILES['img']['tmp_name'],FTP_BINARY,0);
echo ftp_pwd($connect).'/'.$newFileName;
ftp_close($connect);
|