【发布时间】:2015-11-13 10:28:40
【问题描述】:
我尝试将图像上传到服务器,但我无法访问该文件夹,因此我使用了 FTP 连接。通过 android 应用程序,我对图像进行了编码并将其发送到服务器。在服务器端,我只是对其进行解码并尝试上传。但我无法上传它。你能帮我解决这个问题吗?
<?php
// Get image string posted from Android App
$base=$_REQUEST['image'];
// Get file name posted from Android App
$filename = $_REQUEST['filename'];
// Decode Image
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$ftp_server = "";
$ftp_user_name = "";
$ftp_user_pass = "";
$destination_file = "/upload/images/".time().jpg";
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name,$conn_id";
}
$upload = ftp_put($conn_id, $destination_file, $binary, FTP_BINARY);
if (!$upload) {
echo "FTP upload has failed! $upload";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
ftp_close($conn_id);
?>
【问题讨论】:
-
你有什么错误吗?
-
是的,我遇到了以下问题,\n
警告:ftp_put(PNG)[]:打开流失败:.php 文件中的参数无效