将图像上传到服务器时:前置摄像头照片工作/后置摄像头照片不能

时间:2015-05-20 22:52:10

标签: php android

我有一个应用程序,我在其中选择图像并成功上传。我的问题是我只能上传自拍相机前照片。如果我选择使用后置摄像头拍摄的照片,我会收到来自服务器的错误,告诉我它没有收到任何文件,因为此行返回false if (isset($_FILES['image']['name']))。我该如何解决这个问题?

我在画廊中查看过,两者的格式相同:JPEG。

这是我的PHP。

<?php

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

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

// getting server ip address
$server_ip = "IP";

// final file url that is being uploaded
$file_upload_url = 'http://' . $server_ip . '/' . 'AndroidFileUpload' . '/' . $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);
exit;
?> 

1 个答案:

答案 0 :(得分:0)

我认为问题在于图像的大小。

前置摄像头质量较小=尺寸较小。

如果文件大小超过上传限制,则php会将文件作为表单数据排除。

检查phpinfo()中的“upload_max_filesize”和“post_max_size”。 测试是否会上传两个值。