【问题标题】:Image Uploading from android application to Server is not working从android应用程序上传到服务器的图像不起作用
【发布时间】:2015-06-22 05:57:33
【问题描述】:

我正在开发一个需要将相机拍摄的图像上传到服务器的安卓应用程序。我为此使用了一个教程并导入了该项目 from this link, refer this for android code

我的 PHP 文件指示图像成功并返回 URL 但在服务器上找不到图像。我无法解决此问题。

我的PHP文件代码是:

 <?php

// Path to move uploaded files
$target_path = "Upload_image_ANDROID/";

// array for final json respone
$response = array();

// getting server ip address
$server_ip = '216.86.147.200';

// final file url that is being uploaded
$file_upload_url = 'http://' . $server_ip . '/' . 'sss_api' . '/' . $target_path;


if (isset($_FILES['image']['name'])) {
    $target_path = $target_path . basename($_FILES['image']['name']);

    // reading other post parameters
   // $email = isset($_POST['email']) ? $_POST['email'] : '';
    //$website = isset($_POST['website']) ? $_POST['website'] : '';

    $response['file_name'] = basename($_FILES['image']['name']);
    //$response['email'] = $email;
    //$response['website'] = $website;

    try {
        // Throws exception incase file is not being moved
        if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
            // make error flag true
            $response['error'] = true;
            $response['message'] = 'Could not move the file!';
        }

        // File successfully uploaded
        $response['message'] = 'File uploaded successfully!';
        $response['error'] = false;
        $response['file_path'] = $file_upload_url . basename($_FILES['image']['name']);
    } catch (Exception $e) {
        // Exception occurred. Make error flag true
        $response['error'] = true;
        $response['message'] = $e->getMessage();
    }
} else {
    // File parameter is missing
    $response['error'] = true;
    $response['message'] = 'Not received any file!F';
}

// Echo final json response to client
echo json_encode($response);
?>

【问题讨论】:

  • 你能添加一些 echo 语句来看看你的变量的值是什么

标签: php android server android-camera


【解决方案1】:

如果您按照教程完成并且您的 Android 应用程序在您的设备上按预期运行,则问题更多出在服务器端,由于权限,您的服务器不允许您保存文件。

尝试将位置设置为您的应用程序有权写入或更改的文件夹htaccess您可以在http://httpd.apache.org/docs/2.2/howto/htaccess.html获得更多信息

【讨论】:

    猜你喜欢
    • 2017-02-15
    • 2015-02-23
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    • 2012-03-10
    • 2014-04-25
    相关资源
    最近更新 更多