mui+php从服务器下载图片并显示
时间: 2023-12-24 07:06:19 浏览: 39
要从服务器下载图片并显示,可以使用以下步骤:
1. 使用 PHP 代码从服务器下载图片。例如,使用 `file_get_contents` 函数:
```php
$imageUrl = 'http://example.com/image.jpg';
$imageData = file_get_contents($imageUrl);
```
2. 将下载的图片数据存储在本地文件中。例如,使用 `file_put_contents` 函数:
```php
$imageFile = 'image.jpg';
file_put_contents($imageFile, $imageData);
```
3. 在 HTML 中使用 `<img>` 标签来显示图片。例如:
```html
<img src="image.jpg" alt="Image">
```
完整的示例代码如下:
```php
<?php
$imageUrl = 'http://example.com/image.jpg';
$imageData = file_get_contents($imageUrl);
$imageFile = 'image.jpg';
file_put_contents($imageFile, $imageData);
?>
<!DOCTYPE html>
<html>
<head>
<title>Download and Display Image</title>
</head>
<body>
<img src="image.jpg" alt="Image">
</body>
</html>
```