[英]How do I set React (create-react-app) to display image
I have create-react-app application and I am unable to display the image.我有 create-react-app 应用程序,但无法显示图像。 In a code I have
在我的代码中
<img src="/files/2k28WHrMCJu9jSEEss0Y9sKV7Oqf4b/0/120" alt="" />
use .htaccess使用 .htaccess
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^files/(.*)$ /files/files.php?url=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [QSA,L]
it should transfer to它应该转移到
<img src="/files/files.php?url=2k28WHrMCJu9jSEEss0Y9sKV7Oqf4b/0/120" alt="" />
folder structure app is:文件夹结构应用程序是:
|- build
|- files
| |- files.php
|- public
| |- .htaccess
| |- api
| |- ...
|- src
| |- folders with all pages, components, ...
|- storage
| |- all images
PHP code (files.php) returns PHP 代码(files.php)返回
header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
header("Cache-Control: must-revalidate");
header('Expires:'. gmdate('D, d M Y H:i:s', time() + $expiry) .' GMT');
header('ETag: '. $etag);
header("Content-Type: image/jpeg");
header("Content-Length: ". filesize($file));
readfile($file);
If I run the application in build mode (from the build directory), everything works perfectly.如果我在构建模式下(从构建目录)运行应用程序,一切都会完美运行。 It doesn't work in a development environment.
它在开发环境中不起作用。 What is the reason that it works in build mode and not in development mode.
它在构建模式下而不是在开发模式下工作的原因是什么。 Is the reason a directory structure or a proxy or something else?
原因是目录结构还是代理或其他原因?
In your react app put the images under public/static/images
and address them like this:在您的反应应用程序中,将图像放在
public/static/images
下,并像这样处理它们:
<img src="/static/test.jpg" alt="test" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.