]."/> ].">

Home  >  Article  >  Backend Development  >  How to modify avatar in php?

How to modify avatar in php?

coldplay.xixi
coldplay.xixiOriginal
2020-07-23 09:10:223435browse

How to modify the avatar in php: first click on the avatar picture; then in the pop-up selection window, select one of them and the window will launch the avatar change. The code is [a4fb0b998719bdb27f65b5895ac8d08e2cacc6d41bbb37262a98f745aa00fbf0].

How to modify avatar in php?

php method to modify the avatar:

First click on the avatar picture, a selection window will pop up, select one of them and the window Introducing avatar replacement.

Effect:

Main page code:

<tr>
    <td>头像:</td>
    
    <td><input type="hidden" name="face" value=""/>
    <img src="./face/m01.gif" alt="头像" class="face" id=&#39;faceimg&#39; onclick="javascript:window.open(&#39;face.php&#39;,&#39;face&#39;,&#39;width=420,height=600,top=0,left=0,scrollbars=1&#39;);"/></td>
</tr>

Sub-page code (pop-up form page):

    <!-- 使用遍历文件夹函数,获取头像 -->
    <?php $facearray = _myreaddir(dirname(__FILE__)."/face"); ?>
    <div id="face">
        <h3>请选择头像:</h3>
        
            <?php foreach ($facearray as $num){
                    echo "<img src=&#39;face/".$num."&#39; alt=&#39;face/".$num."&#39; title=&#39;".$num."&#39;/>";
            }?>
    </div>

JS code used:

Quote:

    <!-- 点击更换头像 -->
    <script type="text/javascript" src="./js/face.js"></script>

Code:

window.onload =  function() {
    //获取face.php页面中的头像对象
    var img = document.getElementsByTagName(&#39;img&#39;);
    //进行循环
    for(i=0;i<img.length;i++){
        //对选择的对象触发点击事件
        img[i].onclick = function (){
            //调用 _opener()函数
            _opener(this.alt);
        };
    }
}
//显示头像函数
function _opener(src){
    //获取父页面头像对象
    var faceimg = opener.document.getElementById(&#39;faceimg&#39;);
    //将头像的img更换
    faceimg.src = src;
    //将父页面中的register表单中的name为face的值更改为src。
    opener.document.register.face.value = src;
}

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of How to modify avatar in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn