【问题标题】:How to capture mouse cursor location over my uploaded image in html and php?如何在 html 和 php 中捕获我上传的图像上的鼠标光标位置?
【发布时间】:2015-11-09 15:05:20
【问题描述】:

我只想在我上传的图片上写文字。我只使用 html 和 php。 同样,我试图保存用户单击图像以编写文本的鼠标光标的位置。 我在下面尝试了这些东西。 它在我的 click.php 中显示错误。

  1. index.php

    <form action="click.php" method="post" enctype="multipart/form-data">
        <h3>Select image to upload:<br/></h3>
        <input type="file" name="fileToUpload" id="fileToUpload" accept="image/*"/>
        <input type="submit" value="Upload Image" name="submit"/>
    </form>
    
  2. 点击.php

        <script>
        function getPos(e){
            x=e.clientX;
            y=e.clientY;
            cursor="Your Mouse Position Is : " + x + " and " + y ;
            document.getElementById("displayArea").innerHTML=cursor
        }
    
        function stopTracking() {
            document.getElementById("displayArea").innerHTML="";
        }
        </script>
    
        <div id="focusArea" onmousemove="getPos(event)" onmouseout="stopTracking()">
        <?php
            $target_dir = "uploads/";
            $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
              //Set the Content Type
            header("Content-type: image/png");
              #dispaly the image
            $file = $_POST['file'];
            echo file_get_contents($file);
        ?>
        </div>
        <p id="displayArea"></p>
    

【问题讨论】:

    标签: php html image mouseover


    【解决方案1】:

    请试试这个

    $(document).ready(function(e) {
        $('#A').click(function(e) {
            alert(e.pageX+ ' , ' + e.pageY);
        });    
    });
    

    DEMO

    【讨论】:

    • 我们可以在上传的图片的特定区域画一个圆形或一个形状吗?并将该区域保存在 MySQL 数据库中?我尝试了画布,但无法帮助我!
    • @Hytool 您需要将点击的位置添加到数组中,然后插入
    • @RinoRaj u 建议我使用 javascript 的方式。我只能使用 php 和 html。请给我建议同样的方法。
    • 感谢您的回复,用户不会点击上传的图像,用户将拖动鼠标并在图像上绘制形状,我想将该形状存储在数据库中并想获取它根据要求恢复上传的图像。
    猜你喜欢
    • 1970-01-01
    • 2010-10-29
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    相关资源
    最近更新 更多