首页  >  问答  >  正文

php 加载的文件 css js返回给html没有效果是什么问题呢?

PHP代码

          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内容

html{
  font-size: 100px;
}

html内容

自动换行    
<!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 是这样加载css文件的:

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

拆解 /res/public/css/style.css

/res/ 模块

取得真实路径  www\app\public\res\css\style.css 并读取返回内容。

实际样式没有应用成功

1.png

2.png

这是为什么呢?跪求高手解答

P粉477388163P粉477388163826 天前1300

全部回复(4)我来回复

  • 大瓶可乐@php.cn

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

    html{font-size:100px} 换成 p呢?

    回复
    0
  • P粉477388163

    没用,任何样式都没有应用成功。只是内容是读取到的。

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

    http://127.0.0.1/res/public/css/style.css 你这个是一个伪静态呀

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

    可以吧css 写入到文件里面 下次在判断文件是否存在,存在就不用去写入了! 然后直接正常css引用那个CSS文件

    大瓶可乐@php.cn · 2022-06-14 12:12:57
  • 取消回复