繁体   English   中英

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

[英]Android - Display all images from server folder using PHP in GridView

我正在尝试使用相机捕获图像或录制视频,然后将其上传到我的服务器。 在服务器端,我使用PHP语言读取文件并将其移至特定位置。 现在,我要显示存储在服务器中的所有这些图像。 请帮我。

这是上传图片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 . '/' . '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); ?> 

上传相机图片:

在此处输入图片说明

在此处输入图片说明

我想在再次上传图像时显示这些图像同步。

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"; 

我是这方面的新手,因此我们将不胜感激。 非常感谢! 如果需要,我会上传更多详细信息。

让API端点返回您上传的图像的URL,然后从应用程序中调用它们。

喜欢,

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

让它返回一些JSON Array,例如,

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

有一个带有ImageView的自定义GridAdpater 使用像Picasso这样的库,可以通过带有自定义视图的自定义适配器(此处为ImageView )将URL中的图像加载到GridView

每当用户在屏幕上时,都调用此API端点,以便您能够获取已上传照片的列表并每次显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM