如何用PHP更改背景图像? [英] How can I change background image with PHP?

查看:215
本文介绍了如何用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(


< BLOCKQUOTE> BG)-1);


Hello guys,

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆