[英]PHP ftp upload error
我在使用简单的PHP脚本将文件上传到ftp服务器时遇到奇怪的行为。
我创建了以下精简版代码,产生了相同的错误:
<?php
error_reporting(E_ALL);
echo phpversion();
$ftpUrl = "mydomain";
$ftpUserName = "myuser";
$ftpPassword = 'mypass';
$fileContents = "test";
file_put_contents('text.txt', $fileContents);
//open ftp connection
$conn_id = ftp_connect($ftpUrl, 1030);
if(!$conn_id)
die('error while connecting to ftp');
$login_result = ftp_login($conn_id, $ftpUserName, $ftpPassword);
if (!$login_result)
die('ftp login failed!');
//switch to passive mode
ftp_pasv($conn_id, true);
//upload file to ftp
try
{
$fileToUpload = fopen('text.txt', 'r');
if($fileToUpload == false)
die('can\'t open file to send!');
$upload = ftp_fput($conn_id, 'testfile.txt', $fileToUpload, FTP_ASCII);
}
catch(Exception $e)
{
fclose($fileToUpload);
ftp_close($conn_id);
die('Error while uploading to ftp');
}
fclose($fileToUpload);
ftp_close($conn_id);
if (!$upload)
die('ftp upload failed');
?>
在客户端的ftp服务器上,运行脚本时出现以下错误。 (尝试上传文件,建立连接并进行登录时会发生错误)
Warning: ftp_fput() [function.ftp-fput]: php_connect_nonb() failed: Operation now in progress (115) in {path} on line 38
Warning: ftp_fput() [function.ftp-fput]: Type set to A in {path} on line 38
ftp upload failed
服务器使用php版本5.3.28
我已经为这个错误苦苦挣扎了几个小时,这让我发疯。 有什么线索吗?
Ftp_put()将文件名作为参数,您正在传递文件句柄
尝试
ftp_put($conn_id,'testfile.txt', 'test.txt', FTP_ASCII);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.