如何用PHP更改背景图像? [英] How can I change background image with PHP?
问题描述
大家好,
我想问你如何上传图片然后将其路径传递给CSS文件。我创建了一个style.php文件,它正在工作
<?php
header( ' Content-type:text / css');
$ bg = array(' http://placehold.it/320x320',' http://placehold.it/ 350x350',' http://placehold.it/300x300');
$ i = rand(0,count($ bg)-1);
$ selectedBg = $ bg [$ I]跨度>;
?>
正文 {
背景 : url(<?php echo $ selectedBg; ?>);
}
但我不知道如何从另一个页面向数组中添加另一个元素。例如,我想有一个上传按钮,以便我可以稍后更改背景。
bg = array(' http://placehold.it/320x320',' http://placehold.it/350x350',' http: //placehold.it/300x300' 跨度>);
i = rand(0,count(
Hello guys,
< BLOCKQUOTE> BG)-1);
I would like to ask you how I can upload an image and then pass its path to the CSS file. I created a style.php file and it's working <?php
header('Content-type: text/css');
$bg = array('http://placehold.it/320x320', 'http://placehold.it/350x350', 'http://placehold.it/300x300');
$i = rand(0, count($bg)-1);
$selectedBg = "$bg[$i]";
?>
body{
background: url(<?php echo $selectedBg; ?>);
}
But I do not know how to add another element to the array from another page. For example I would like to have an upload button so I can change the background later.bg
= array('http://placehold.it/320x320', 'http://placehold.it/350x350', 'http://placehold.it/300x300');
i
= rand(0, count(
bg)-1);
这篇关于如何用PHP更改背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!