Home > Backend Development > PHP Problem > How to modify avatar in php?

How to modify avatar in php?

coldplay.xixi
Release: 2023-03-02 22:16:01
Original
3547 people have browsed it

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 [].

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>
Copy after login

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

    <!-- 使用遍历文件夹函数,获取头像 -->
    <?php $facearray = _myreaddir(dirname(__FILE__)."/face"); ?>
Copy after login
    <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>
Copy after login

JS code used:

Quote:

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

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;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template