我很难将一个简单的文件从我的桌面上传到我的远程服务器。我在 php 中有一个简单的表单来获取文件:
<form enctype="multipart/form-data">
<tr>
<td><label>select the file to reconcile the checks</label></td>
<td><input type="file" id="file" name="file" /></td>
<td><input type="button" id="checks" value="Check Reconciliation" /></td>
</tr>
</form>
然后将其传递给我的 JavaScript:
$("#checks").live('click', function() {
$.ajax({
type: "POST",
url: "checkReconciliation3.php",
dataType: "json",
data: ({file: $('#file').val()}),
success: function(data){
$('#message').html(data.message);
}
});
}); //end of checks click function
并且checkReconciliation3.php
是:
header('Content-type: text/html; charset=utf-8');
require_once ('../db.php');
require_once('ftp.php');
$file = $_POST['file'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
//ftp_chdir($conn_id, '/home/bookcell/bookcellaronline.com/html/testbcos/accounting/');
ftp_put($conn_id, $remote_file, $file, FTP_BINARY);
echo $php_errormsg;
ftp_close($conn_id); // close the connection
从我对 SO 的所有研究来看,这看起来是正确的,但我不断收到以下错误:
PHP Warning: ftp_put(checkslastmonth.csv) [<a href='function.ftp-put'>function.ftp-put</a>]: failed to open stream: No such file or directory in /chroot/home/bookcell/bookcellaronline.com/html/testbcos/accounting/checkReconciliation3.php
在第 24 行。
第 24 行是
ftp_put($conn_id, $remote_file, $file, FTP_BINARY);
我尝试过使用$file = $_FILES["file"]["name"]
,但我仍然得到同样的错误。我要上传到服务器的文件位于我的桌面上。我怎样才能让它工作?