【发布时间】:2013-12-09 21:44:52
【问题描述】:
我有以下代码
<?php
ini_set('display_errors', 'on');
error_reporting(E_ALL);
$conn = ftp_connect("ftp.MYSITE.com") or die("Failed to connect to FTP server");
ftp_login($conn, "USER", "PASS");
$my_file = 'test.txt';
$file_handler = fopen("test.txt", 'w');
fwrite($file_handler, "A second line");
ftp_fput($conn, "/nick/test.txt", $file_handler, FTP_ASCII);
fclose($file_handler);
ftp_close($conn);
?>
当我运行它时,文件 test.txt 出现在正确的文件夹中,但是 test.txt 文件是空的。为什么会这样,我该如何解决?
【问题讨论】:
-
你试过
ftp_fput($conn, "test.txt", $file_handler, FTP_ASCII);吗?由于您直接在$file_handler = fopen("test.txt", 'w');中访问它,因此还要检查文件权限。 -
是的,做到了,您能解释一下发生了什么变化以及为什么它可以解决问题吗?
-
ftp?这是 2013 年,而不是第 70 年! -
因为文件写入通常不使用绝对路径,而是直接访问时使用相对路径。很高兴看到它对你有用,干杯。
-
@arkascha 你有什么推荐的? SSH?
标签: php file-upload file-io ftp