Php 为什么第二个move_upload_file函数没有';你不能用这个密码吗?
如何在此代码中上载缩略图?Php 为什么第二个move_upload_file函数没有';你不能用这个密码吗?,php,Php,如何在此代码中上载缩略图? 当我点击上传时,它只移动第一个上传的文件,不移动第二个。 有人能帮我吗 <?php if(isset($_POST['submit'])){ $cap = mysqli_real_escape_string($con, $_POST['cap']); $image = $_FILES['image'] ['name']; $tmp_name= $_FILES['image'] ['tmp_name']; $thumb = $_FI
当我点击上传时,它只移动第一个上传的文件,不移动第二个。 有人能帮我吗
<?php
if(isset($_POST['submit'])){
$cap = mysqli_real_escape_string($con, $_POST['cap']);
$image = $_FILES['image'] ['name'];
$tmp_name= $_FILES['image'] ['tmp_name'];
$thumb = $_FILES['thumb'] ['name'];
$tmp_name= $_FILES['thumb'] ['tmp_name'];
$type = $_POST['type'];
if(empty($image) or empty($thumb) or empty($cap)){
$error = "<p style='font-seize: 20px; font-weight: bolder; color: red;'>
Please Fill out all required stared inputs!</p>";
}
else{
$pic = "INSERT INTO photos(image, thumb, caps, type)VALUES('$image', '$thumb', '$cap', '$type')";
if(mysqli_query($con, $pic)){
$success = "<p style='font-seize: 25px; font-weight: bolder; color: green;'>
<i class='fa fa-smile-beam'></i> Your Data
Published Successfully</p>";
move_uploaded_file($tmp_name, "img/photos/$image");
move_uploaded_file($tmp_name, "img/thumbs/$thumb");
}
else{
$fail = "<p style='font-seize: 20px; font-weight: bolder; color: red;'><i class='fa fa-sad-tear'>
</i> Unsuccessful!</p>";
}
}
}
?>
一个变量只能包含一件事。您对图像和拇指都使用了$tmp_name
,第二次赋值后,它只有拇指的临时名称
您需要使用不同的变量
<?php
if(isset($_POST['submit'])){
$cap = mysqli_real_escape_string($con, $_POST['cap']);
$image = $_FILES['image'] ['name'];
$tmp_image= $_FILES['image'] ['tmp_name'];
$thumb = $_FILES['thumb'] ['name'];
$tmp_thumb= $_FILES['thumb'] ['tmp_name'];
$type = $_POST['type'];
if(empty($image) or empty($thumb) or empty($cap)){
$error = "<p style='font-seize: 20px; font-weight: bolder; color: red;'>
Please Fill out all required stared inputs!</p>";
}
else{
$pic = "INSERT INTO photos(image, thumb, caps, type)VALUES('$image', '$thumb', '$cap', '$type')";
if(mysqli_query($con, $pic)){
$success = "<p style='font-seize: 25px; font-weight: bolder; color: green;'>
<i class='fa fa-smile-beam'></i> Your Data
Published Successfully</p>";
move_uploaded_file($tmp_image, "img/photos/$image");
move_uploaded_file($tmp_thumb, "img/thumbs/$thumb");
}
else{
$fail = "<p style='font-seize: 20px; font-weight: bolder; color: red;'><i class='fa fa-sad-tear'>
</i> Unsuccessful!</p>";
}
}
}
?>
一旦移动,从原始位置复制肯定会失败。因为,嗯,它是从那里移动的。先复制,或者复制img/photos/$image
@Barmar我的意思是,我怎么能同时移动两个图像?你能告诉我更多的细节吗?@mario那么我如何能同时将两个图像移动到一个目录中呢?你需要对这两个图像使用不同的变量。您正在使用$tmp\u name
来表示这两个名称。