我試圖上傳圖像到服務器,但我不能有權限訪問文件夾,所以我已經使用FTP連接。通過Android應用程序,我編碼圖像並將其發送到服務器。在服務器端,我只是解碼它,並試圖上傳它。但我無法上傳它。你能幫我解決這個問題嗎?上傳文件到服務器使用FTP在PHP
<?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);
?>
你有什麼錯誤嗎? – lukassteiner
是的,我有以下問題,\ n
警告:ftp_put(PNG)[]:未能打開流:在PHP文件 – Prabha