How can I upload the thumbnail in this code?
When I click upload, it only moves the first move_uploaded file and doesn't move the second one.
Can anyone help me, please?
<?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>";
}
}
}
?>
My Answer:
The second move_uploaded_file function is used to move the uploaded file from the temporary directory to the desired destination directory on the server. This function is necessary to ensure that the uploaded file is stored in the correct location and can be accessed by the server for further processing or storage.
Rate this post
3 of 5 based on 3506 votesComments