我想上傳image
文件在服務器上,因爲沒有找到任何方式直接從CodenameOne上的服務器上傳文件。我以Base64格式轉換圖像併發送到php文件,然後在php再次解碼圖像並嘗試上傳。但同樣也不起作用。你能告訴我我該如何解決這個問題?通過PHP在服務器上傳文件[CodenameOne]
我的PHP代碼:
<?php
define('UPLOAD_DIR', 'public_html/appFiles/GKQuiz/userProfilePicture/');
//$Imagecode=$_POST['Image'];
//Base64 String already added in $Imagecode
$Imagecode="/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABAAEADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAA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JGXbc9lGdpyBHI6hvrknP8An61zzMCQ6oUGOhPX9PSgMUG3GP8AdIz9atTktmQ4piJxjcRkdD6Uu4rhmJJxtyTjt0xTTlifkOM4yOSMf/WpYbeSbaiEhXbGSOOlTexSV9hyyRliXAOO2euOlXBbzWQWVANyqDyOmcj8Dz2qSytbeNA7yp5/AAyQF5zuyO449e/oM22t/tjeY7PsG1c5w20A5wMjJ6DNYyq2fkbRpXXmZsTxxCUM6uzpnGM4+h9ec+nHrUNxDLFKEVzIwAJw3cjPH+NT3FtMYGvImxAcLgvlj6ZHfp9Pl9qqCdo4niJJJYZ59M/4mtE77GTVtx5uY1EexPLdBgkHduOTyCenYfhmpYxHJIFEgaPJPGQW9BgDOTjjsMj3quwWVUJUbjxwep9sf1pjQyKgbDFV49h1/wD11VhXP//Z";
$img=base64_decode($Imagecode);
//echo $img;
$uid=uniqid();
$ftp_server = "example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to ftp_server");
$login = ftp_login($ftp_conn, "example.com", "123");
if (ftp_put($ftp_conn, UPLOAD_DIR . $uid . ".jpg", $img, FTP_BINARY))
{
echo "Successfully uploaded";
}
else{
echo "Error uploading";
}
// close connection
ftp_close($ftp_conn);
?>
這不起作用 –