Я следую этому руководству.Как разобрать php-сообщение с Java - ошибка неправильного HTTP-формата
Если следовать учебник, я сохранил fileUpload.php к моему серверу.
http://68.169.50.115/AndroidFileUpload/fileUpload.php
И это сообщение. Я получил в формате JSON, когда вы «успешно» сохранили изображение на сервере. Проблема в том, что ссылка не работает, и фактическое изображение на самом деле не сохраняется на моем сервере.
private void showAlert(String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message).setTitle("Response from Servers")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do nothing
}
});
Log.d("OGG", "JSON: " + message);
AlertDialog alert = builder.create();
alert.show();
}
}
Это ответ от сообщения Log.d, сообщение JSON, образованное изображением.
03-13 16: 40: 24.725: D/OGG (5158): Ссылка: {"error": false, "message": "Файл загружен успешно!", "File_path": "http: //68.169 .50.115/AndroidFileUpload/IMG_20150313_164010.jpg "}
Это говорит о том, что картина существует, но если вы пытаетесь ссылку ..
http://68.169.50.115/AndroidFileUpload/IMG_20150313_164010.jpg
It не работает.
Не работает ли он должным образом, потому что у меня есть файл php, сохраненный на моем облачном сервере, а не на моем персональном компьютере, как диктует учебник?
Почему файл фактически не сохраняется.
Вот файл upload.php
<?php
// Path to move uploaded files
$target_path = "uploads/";
// array for final json respone
$response = array();
// getting server ip address
$server_ip = gethostbyname(gethostname());
// final file url that is being uploaded
//$file_upload_url = 'http://' . $server_ip . '/';
$file_upload_url = 'http://' . $server_ip . '/' . 'AndroidFileUpload' . '/';
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'] : '';
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);
?>
я смог его Работа. Взгляните на мой обновленный ответ. –