你能有一个弹出窗口而不去php中的新页面吗

  • 本文关键字:php 新页面 有一个 窗口 php
  • 更新时间 :
  • 英文 :


我正试图在用户上传图片后弹出一个窗口。我得到了弹出窗口,唯一的事情是它首先将他们带到一个新的页面。我希望弹出窗口,而不需要用户先进入新页面。

这是我的代码

<?php
$target_dir = "../images/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(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) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 30000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if ( $imageFileType != "jpg" && $imageFileType != "png"
&& $imageFileType != "jpeg" && $imageFileType != "gif") 
{
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded.";
copy($target_file, 'images/' . $target_file);
} else {
echo "Sorry, there was an error uploading your file.";
}
}

是的,你可以


PHP是服务器端的,但您仍然可以使用客户端代码

以下是我们如何使用php弹出窗口:

<body>
<div class="popup">
<div class="popup-content">
<span>Hello World</span>
<p>This is my very very cool popup !</p>
<button onclick="closePopup();"></button>
</div>
</div>
<script>
function closePopup {
var popup = document.querySelecter(".popup");
popup.style.display = "none";
}
</script>
这是带有一些Javascript的html代码,首先我建议您尝试一下这些代码并使用css,这样它看起来不错。

将其添加到php


<?php
echo '<body>
<div class="popup">
<div class="popup-content">
<span>Hello World</span>
<p>This is my very very cool popup !</p>
<button onclick="closePopup();"></button>
</div>
</div>
<script>
function closePopup {
var popup = document.querySelecter(".popup");
popup.style.display = "none";
}
</script>
</body>';

因此,您可以随时回显一些Html代码。

其他方式


是的!我们甚至还有别的办法。我们将使用Javascript

<body>
<div class="popup">
<div class="popup-content">
<span>Hello World</span>
<p>This is my very very cool popup !</p>
<button onclick="closePopup();"></button>
</div>
</div>
<script>
function openPopup() {
var popup = document.querySelecter(".popup");
popup.style.display = "block";
}
function closePopup() {
var popup = document.querySelecter(".popup");
popup.style.display = "none";
}
closePopup();
</script>
</body>
<?php

if(1 === 1) 
{
echo "openPopup();";
}
##

最新更新