gpt4 book ai didi

php - 图片未显示在页面上-在新标签页中打开会显示index.php

转载 作者:行者123 更新时间:2023-12-02 19:21:06 26 4
gpt4 key购买 nike

我在index.php文件中放置了一些图像,但奇怪的是它没有显示出来,以前从未出现过此问题。
这是我用来显示图像的一些代码

<img class="lozad" alt="Twitter" data-src="public/resources/images/twitter.svg" src="public/resources/images/twitter.svg" data-loaded="true">

<img src="public/resources/images/twitter.svg" height="100" width="80"/>

<img src="resources\images\youtube.svg" height="100" width="80"/>
我的style.less可以工作,并且在同一文件夹中
<style type="text/less"><?php echo file_get_contents('resources/style.less'); ?></style>
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/3.9.0/less.min.js" ></script>
Broken images
我编写了以下代码,向我展示目录中的内容。
foreach(glob(__DIR__.'/resources/images/*.*') as $file) {
echo $file;
}
die;
这将返回:

/var/www/html/public/resources/images/twitter.svg

/var/www/html/public/resources/images/youtube.svg


另外,我不确定这是否重要,但是我也在使用docker,下面是一些相关文件:
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Docker文件
ARG APACHE_VERSION=""
FROM httpd:${APACHE_VERSION:+${APACHE_VERSION}-}alpine

RUN apk update; \
apk upgrade;

# Copy apache vhost file to proxy php requests to php-fpm container
COPY demo.apache.conf /usr/local/apache2/conf/demo.apache.conf
RUN echo "Include /usr/local/apache2/conf/demo.apache.conf" \
>> /usr/local/apache2/conf/httpd.conf
demo.apache.conf
ServerName localhost

LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so

<VirtualHost *:80>
DocumentRoot "/var/www/html/public"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/vnd.api+json
</IfModule>
<IfModule mod_headers.c>
Header always set Access-Control-Allow-Headers "authorization, content-type"
Header always set Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE"
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Expose-Headers "authorization"
</IfModule>
<Directory "/var/www/html/public">
<IfModule mod_rewrite.c>
RewriteEngine On
# Handle options requests...
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^ - [R=204,L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Handle Front Controller...
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
nginx.conf
events {}
http {
server {
access_log /dev/stdout;
error_log stderr;
gzip on;
gzip_types application/vnd.api+json;
location / {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, PATCH, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'authorization, content-type' always;
add_header 'Access-Control-Expose-Headers' 'authorization' always;
if ($request_method = 'OPTIONS') {
return 204;
}
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
}
}
}
docker-compose.yml
version: "3.2"
services:
nginx:
ports:
- 80:80
image: nginx:1.17
volumes:
- ./docker/nginx.conf:/etc/nginx/nginx.conf:ro

php:
image: php:7.4-fpm
volumes:
- .:/var/www/html
database:
image: mysql:5.7.26
command: --explicit_defaults_for_timestamp
volumes:
- mysql-data:/var/lib/mysql
environment:
MYSQL_DATABASE: 'db'
MYSQL_USER: 'user'
MYSQL_PASSWORD: *********************
MYSQL_ROOT_PASSWORD: *********************
volumes:
mysql-data:

最佳答案

每次提到nginx.conf中的mime类型和 friend 的一些重新设计后,主要问题是nginx.conf,它应如下所示

events {}

http {
include mime.types;
server {
access_log /dev/stdout;
error_log stderr;
root /var/www/html/public;

gzip on;
gzip_types application/vnd.api+json;

location / {
try_files $uri @php;
}

location @php {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, PATCH, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'authorization, content-type' always;
add_header 'Access-Control-Expose-Headers' 'authorization' always;

if ($request_method = 'OPTIONS') {
return 204;
}

fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
}
}
}

关于php - 图片未显示在页面上-在新标签页中打开会显示index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59676257/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com