将文件/图像从android上传到远程服务器

时间:2014-09-19 20:17:19

标签: php android file-upload bitmap

我试图通过PHP - ftp_put()函数将捕获的图像从Android设备上传到远程服务器。 Android代码正在运行,我只是不从php端开始工作。

说明:在Android / Java端,我将位图编码为字符串并在PHP中解码($ binary)。我想将此位图上传到远程服务器。请参阅我的PHP代码:

<?php

if ($tag == 'upload') {

        //Get data from client
        $uid = $_POST['uid'];
        $base = $_POST["image"];
        $date = date('Y-m-d-H-m-s');

        if (isset($base)) {
            //function creates random numbers and stores in $suffix
            $suffix = $db->createRandomID(); 

            //Prepare image name
            $image_name_ = "img_".$suffix."".$uid."_".date("Y-m-d-H-m-s").".jpg";

            // base64 encoded utf-8 string
            $binary = base64_decode($base);

            // binary, utf-8 bytes
            header("Content-Type: bitmap; charset=utf-8");

            //Basic ftp information
            $ftp_server = "xxx.xxx.com";
            $ftp_user_name = "xxxxx";
            $ftp_user_pass = "xxxxx";
            $file = $binary;
            $remote_file = "/public_html/uploads/".$image_name_;

            // set up basic connection
            $conn_id = ftp_connect($ftp_server);

            // login with username and password
            $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

            // upload a file
            if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
            $response["success"] = "Upload";
            echo json_encode($response);

            } else {
            $response["error"] = "failed";
            }

            // close the connection
            ftp_close($conn_id);
        }
?>

LogCat说:没有这样的文件或目录......行if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII))

0 个答案:

没有答案