Home » Php » Check before upload php

Check before upload php

Posted by: admin February 25, 2020 Leave a comment


I am trying to upload file without duplication but my codes is not right.

                    $stud_no = $_POST['stud_no'];
                    $file_name = $_FILES['file']['name'];
                    $file_type = $_FILES['file']['type'];
                    $file_temp = $_FILES['file']['tmp_name'];
                    $location = "files/".$stud_no."/".$file_name;
                    $date = date("Y-m-d, h:i A", strtotime("+8 HOURS"));
                    if(!file_exists('files/'.$stud_no.'/'.$file_name)){ //Check the file
                    $message ='File already exist! Please rename your file '.$file_name.'';
                    echo "<script language='javascript'>alert('$message');window.location.replace(\"student_profile.php\");</script>"; 
                    else { 
                        move_uploaded_file($file_temp, $location);
                        mysqli_query($conn, "INSERT INTO `storage` VALUES('', '$file_name', '$file_type', '$date', '$stud_no')") or die(mysqli_error());
                        header('location: student_profile.php');
How to&Answers: