动态生成html文件以显示图像和视频


Dynamically generate html files to display image and video

我正在上传一些图像和视频到上传文件夹,然后我使用数组将它们显示到我的网页上。这会给浏览器带来额外的负载。所以我希望当我上传任何图像/视频到上传文件夹时,它应该创建动态html或php文件来显示每个图像/视频。有人能告诉我怎么做吗?

我建议您编写两个模板(视频和图像),并使用file_gets_contents和str_replace()以及file_put_contents

我的想法示例:

templateVideo.html(或者php,如果需要动态)

<html>
<head>
    <title></title>
</head>
<body>
    <video src="YOUR_DYNAMIC_PATH"></video>
</body>
</html>

upload.php:

# ... your code for upload ...
$videoName = 'myFile.mp3';
$myTemplate = file_get_contents('templateVideo.html');
//str_replace(search, replace, subject)
$myTemplate = str_replace('YOUR_DYNAMIC_PATH', $videoName, $myTemplate);
// file_put_contents(filename, data)
file_put_contents('your_path_and_filename', $myTemplate);

类似的东西:)

注意:如果您需要

,请查看mkdir以创建动态文件夹