Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-02 18:44:01 09月23日 Update

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!

Tags: Pictures files folders paths problems content more knowledge parts output practical learned and then code functions front-end methods dilemmas practical what to do Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi vpn NVidia Linux