gpt4 book ai didi

php - 文件上传按钮在翻转卡上不起作用

转载 作者:行者123 更新时间:2023-12-05 07:03:19 28 4
gpt4 key购买 nike

我已经完成了 html 和 PHP 代码的文件 uploader 按钮,但是当我尝试测试它以查看它是否可以在浏览器中工作时,我从文件夹中选择了一个图像,然后我选择了我选择的任何图像“提交”翻页卡上什么都没有出现,我不确定为什么什么都没有出现

<!--flip card code.-->
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}

.flip-card {
background-color: transparent;
width: 300px;
height: 300px;
perspective: 1000px;
}

.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.6s;
transform-style: preserve-3d;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
}

.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
}

.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}

.flip-card-front {
background-color: #bbb;
color: black;
}

.flip-card-back {
background-color: #2980b9;
color: white;
transform: rotateY(180deg);
}
</style>
</head>
<body>
<h1>Card Flip with Text</h1>
<h3>Hover over the image below:</h3>
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
</div>
<div class="flip-card-back">
</div>
</div>
</div>
</body>
</html>
<!--Flip card code-->


<!-- File uploader button code-->
<html>
<body>

<form action="action_page.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="file">
<button type="submit" name="submit">UPLOAD</button>
</form>

</body>
</html>
<!--action_page.php code-->

<?php
if(isset($_POST["submit"])) {
$file = $_FILES['file'];

$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];

$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));

$allowed = array('jpg', 'jpeg', 'png', 'pdf');

if (in_array($fileActualExt, $allowed)){
if ($fileError === 0){
if($fileSize < 100000){
$fileNameNew = uniqid('', true).".".$fileActualExt;
fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file(fileTmpName, $fileDestination);
header("Location: index.php?uploadsuccess");

} else {
echo "Your file is too big!";
}

} else {
echo "There was an error uploading your file";
}

} else {
echo "You cannot upload files of this type!";
}
}
?>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="/__/firebase/7.14.2/firebase-app.js"></script> <!--specifies the URL of an external script file-->

<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->

<script src="/__/firebase/7.14.2/firebase-analytics.js"></script> <!--specifies the URL of an external script file-->

<!-- Initialize Firebase -->
<script src="/__/firebase/init.js"></script> <!--specifies the URL of an external script file-->
<script type="text/javascript" src="cordova.js"></script> <!--specifies the media type of the script-->
<script type="text/javascript" src="js/index.js"></script> <!--specifies the media type of the script--></body>
</html>

最佳答案

除了“fileActualExt”之外一切都很好!查看您忘记连接实际扩展名的 $fileNameNew。相反,您编写的 fileActualExt 就像一个常量。

正确的代码是$fileNameNew = uniqid('', true).".".$fileActualExt;

不要忘记在 action_page.php 文件所在的目录中创建 uploads 文件夹。

<?php
if(isset($_POST["submit"])) {
$file = $_FILES['file'];

$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];

$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));

$allowed = array('jpg', 'jpeg', 'png', 'pdf');

if (in_array($fileActualExt, $allowed)){
if ($fileError === 0){
if($fileSize < 100000){
$fileNameNew = uniqid('', true).".".$fileActualExt; // concatination of uniqueid and fileActualExt
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
header("Location: index.php?uploadsuccess");

} else {
echo "Your file is too big!";
}

} else {
echo "There was an error uploading your file";
}

} else {
echo "You cannot upload files of this type!";
}
}
?>

关于php - 文件上传按钮在翻转卡上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63269712/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com