[英]mouse location tracking on uploaded image using html and javascript
我已經編寫了用於跟蹤鼠標位置的代碼,但是我的代碼僅適用於字符串,而不適用於我上傳的圖像。 它正在生成圖像圖標,而不是圖像。
<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/*"/>
click.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>
</head>
<body>
<div id="focusArea" onmousemove="getPos(event)" onclick="merge" onmouseout="stopTracking()">
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if (isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if ($check !== false) {
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
$uploadOk = 1;
} else {
$uploadOk = 0;
}
}
header("Content-type: image/png");
imagepng($target_file);
imagedestroy($target_file);
?>
</div>
<p id="displayArea"></p>
標題不能在任何后面設置,它們必須是任何輸出的第一行。
這行:
header("Content-type: image/png");
不屬於那里。 啟用錯誤,如下所示:
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
並且您將收到錯誤消息,告訴您無法設置標題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.