Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of not displaying the pictures in the folder obtained by php

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to solve the problem that the pictures in the php access folder do not display". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Php access folder pictures do not display the solution: 1, read the picture through readfile or get_file_contents; 2, modify the HTML code such as "var pic=" {: url ('/ home/showPics')} "+'? pic='+item;".

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

What if the pictures in the php get folder are not displayed?

PHP reads pictures from a folder (such as a shared folder) and displays:

1. Get the pictures under the folder

Public function albumList () {$share_url = input ('path'); $files = getImgList ($share_url); / / output image path list in json format} / / get picture file list function function getImgList ($dir) {$files = array (); if (is_dir ($dir)) {$file_dir = scandir ($dir) Foreach ($file_dir as $file) {if ($file = ='.'| | $file = ='..') {continue;} elseif (is_dir ($dir.$file.'/')) {$files = array_merge ($files, getImgList ($dir.$file.'/')) } else {if (isImage ($dir.$file)! = = false) {array_push ($files, $dir.$file);}} return $files;}

two。 When the front end is directly used to display the picture path, the picture cannot be displayed normally, but the path picture in src is displayed normally when it is opened directly.

Problem solving:

To read the images in the file, you need to read by readfile or get_file_contents. The solution is as follows:

Php section:

/ / share the picture public function showPics () {$pic = input ('pic',''); / / the file path where the picture is located is header (' Content-Type: image/jpeg'); readfile ($pic);}

Html section:

Var pic= "{: url ('/ home/showPics')}" +'? pic='+item; / / item is the image path eg:\\ 192.168.199.176\ 20200522153602501004911\ 1.png

The picture is displayed normally:

This is the end of the content of "how to solve the problem that the pictures in the php access folder do not display". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report