Home  >  Q&A  >  body text

What is the problem if the file loaded by php, css, js and returned to html has no effect?

PHP code

          ob_end_clean();
          ob_start();

          //读取文件mimetype信息
          $finfo = finfo_open(FILEINFO_MIME);
          $mimetype = finfo_file($finfo, $uri);
          finfo_close($finfo);

          //打开文件
          $file    = fopen($uri, 'r');
          $file_size  = filesize($uri);
          //声明头信息
          Header("Content-type: $mimetype");
          Header("Accept-Ranges: bytes");
          Header("Accept-Length: ".$file_size);
         
          // 输出文件内容
          echo fread($file,$file_size);
          fclose($file);

css content

html{
  font-size: 100px;
}

html content

自动换行    
<!DOCTYPE html>    
<html lang="zh-CN">    
<head>    
<meta charset="UTF-8">    
<meta http-equiv="X-UA-Compatible" content="IE=edge">    
<meta name="viewport" content="width=device-width, initial-scale=1.0">    
<link rel="stylesheet" href="http://127.0.0.1/res/public/css/style.css">    
<title>test</title>    
</head>    
<body>    

hello world

     </body>     </html>

php Yes Load the css file like this:

http://127.0.0.1/res/public/css/style.css

Disassemble/res/public/css/style.css

/res/ Module

Get the real path www\app\public\res\css\style.css and read the returned content.

The actual style was not applied successfully

1.png

2.png

##Why is this? Woolen cloth? I beg the experts for answers

P粉477388163P粉477388163817 days ago1295

reply all(4)I'll reply

  • 大瓶可乐@php.cn

    大瓶可乐@php.cn2022-06-13 21:09:10

    html{font-size:100px} What about replacing it with p?

    reply
    0
  • P粉477388163

    No use, none of the styles were successfully applied. Only the content is read.

    P粉477388163 · 2022-06-14 07:43:17
    大瓶可乐@php.cn

    http://127.0.0.1/res/public/css/style.css This is a pseudo-static

    大瓶可乐@php.cn · 2022-06-14 12:10:18
    大瓶可乐@php.cn

    Yes, you can write the css into the file. Next time, you will determine whether the file exists. If it exists, you don’t need to write it! Then directly reference that CSS file with normal css

    大瓶可乐@php.cn · 2022-06-14 12:12:57
  • Cancelreply