Android - 在GridView中使用PHP显示服务器文件夹中的所有图像

I am trying to capture image or record a video using camera and then upload to my server. On the server side, i used PHP language to read the file and moved it to a particular location. Now i want to display all these images that are stored my server. Please help me.

This is the upload image PHP script

<?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 . '/' . '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);
?>

upload Camera image:

enter image description here

enter image description here

i want to display theses images synchronised when i upload images again.

Config.java

public class Config {
// File upload url (replace the ip with your server address)
public static final String FILE_UPLOAD_URL = "http://wangjian.site90.net/AndroidFileUpload/fileUpload.php";
// Directory name to store captured images and videos
public static final String IMAGE_DIRECTORY_NAME = "Android File Upload";

I'm a newbie at this stuff so any help will be appreciated. thanks so much! And i will upload more details if needed.

</div>

Have an API endpoint return the URLs of the images that you have uploaded and then call them from the app.

Like,

public static final String FILE_DOWNLOAD_URL = "http://wangjian.site90.net/AndroidFileUpload/getUserPhotos.php";

Let this return some JSON Array like,

{
   "urls" : [
     {   
        "url" : "url of pic 1"
     },
     {
        "url" : "url of pic 2"
     },
     ..
    ]
}

Have a custom GridAdpater with an ImageView in it. Use libraries like Picasso to load the images from the url into your GridView using the custom adapter with a custom view (Here, ImageView).

Call this API endpoint every time when the user is on the screen so that you'll be able to fetch the list of uploaded photos and show them everytime.