- 此问题在此处已有答案**:
PHP ftp_put fails(2个答案)
3小时前关门了。
我正在使用一个脚本通过php脚本上传文件到我的ftp服务器。连接是好的,但每次我试图上传文件,它说:上传文件时出错!请稍后重试。
所以这个剧本好像有问题。
目录目标为mydomain/test/upload/,脚本位于:mydomain/test/index.php
你们谁能帮我弄明白?
// ftp settings
$ftp_hostname = 'xxxx'; // change this
$ftp_username = 'xxxx'; // change this
$ftp_password = 'xxxx'; // change this
$remote_dir = '/upload/'; // change this
$src_file = $_FILES['srcfile']['name'];
if ($src_file!='')
{
// remote file path
$dst_file = $remote_dir . $src_file;
// connect ftp
$ftpcon = ftp_connect($ftp_hostname) or die('Error connecting to ftp server...');
// ftp login
$ftplogin = ftp_login($ftpcon, $ftp_username, $ftp_password);
// ftp upload
if (ftp_put($ftpcon, $dst_file, $src_file, FTP_ASCII))
echo 'File uploaded successfully to FTP server!';
else
echo 'Error uploading file! Please try again later.';
// close ftp stream
ftp_close($ftpcon);
}
else
header('Location: index.php');
所述索引文件为:
<!DOCTYPE html>
<html>
<head>
<title>Upload Files to FTP Server in PHP</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
</head>
<body>
<br/>
<div class="container">
<div class="col-xs-8 col-xs-offset-2 well" style="background:none;">
<form action="ftp_upload.php" method="post" enctype="multipart/form-data">
<legend>Please Choose File to Upload</legend>
<div class="form-group">
<input type="file" name="srcfile" />
</div>
<div class="form-group">
<input type="submit" name="submit" value="Upload File to FTP Server" class="btn btn-warning"/>
</div>
</form>
</div>
</div>
</body>
</html>
我想将文件上载到上载文件夹:mydomain/测试/上传/
1条答案
按热度按时间kxkpmulp1#
要么是源文件不正确,要么是FTP位于防火墙后面。
如果位于防火墙后面,请尝试ftp-pasv