很抱歉,如果我在这里错过了与此类似的问题,但我无法找到答案。所以我使用FTP和PHP将文件从远程服务器上传到我的服务器。这是我的代码。
<?php
if(isset($_POST['remote'])) {
$source = $_POST['remote'];
$filename = time() . ".apk";
$server = "my_server_address";
$user_name = "username";
$password = "password";
try {
if(ftp_connect($server)) {
$connection = ftp_connect($server);
} else {
throw new Exception("Could not connect to FTP server");
}
} catch (Exception $e) {
echo $e->getMessage();
}
ftp_login($connection, $user_name, $password);
ftp_put($connection, $filename, $source, FTP_ASCII);
}
?>
<form method="post">
<input type="text" name="remote">
<input type="submit" value="Upload">
</form>
一切都很顺利。我成功连接到我的服务器,也成功上传了远程文件。但是当我在上传完成后检查我的服务器上的文件时,它会中断(损坏)。
请注意,我正在使用此方法上传Android应用的APK文件(扩展名为.apk)。
对此有何解决方案?请帮忙。
答案 0 :(得分:4)
.apk文件是可执行代码,因此您需要使用FTP_BINARY
代替FTP_ASCII
。