- <?php
- if(isset($_POST['submit_button'])) {
- //theFile is name of file input in html
- if(is_uploaded_file($_FILES['theFile']['tmp_name'])) {
- $sourcePath = $_FILES['theFile']['tmp_name'];
- $fileName=$_FILES['theFile']['name'];
- if (!file_exists("myFolder")) {
- chmod(mkdir("myFolder",755));
- }
- $filePath = "myFolder/".$_FILES['theFile']['name'];
- $filePath = preg_replace('/\s+/', '', $filePath);
- //you can add other field also to save data to database,example
- $fname=$_POST['fname'];
- $lname=$_POST['lname'];
- //etc....
- if(move_uploaded_file($sourcePath,$filePath)) {
- $sql="INSERT INTO Table_name (firstname,firstname,filepath) VALUES('$fname',$lname','$filepath')";
- $results=mysqli_query($con, $sql) or die(mysqli_error($con));
- if ($results) {
- echo "success";
- }else{
- echo "failed";
- }
- }
- }
- }
- ?>
-
- Active Topics
-
-
- by Eli 6 hours ago Re: What is in Your Mind? View the latest post Replies 732 Views 331201
- by Eli 16 hours ago Russia Invades Ukraine View the latest post Replies 674 Views 264780
- by Eli 17 hours ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 334 Views 54735
- by Eli 4 days ago Shared Images View the latest post Replies 6 Views 1649
- by Eli 6 days ago Dr Wahome: How World Health Organization (WHO) is Doing Bad Things View the latest post Replies 1 Views 225
- by Eli 1 week ago Introduction to Abstract Algebra View the latest post Replies 4 Views 11169
- by Eli 1 week ago Generating SSH Key and Adding it to the ssh-agent for Authentication on GitHub View the latest post Replies 2 Views 1309
- by Eli 1 week ago How AI Could Empower any Business View the latest post Replies 1 Views 416
- by Eli 1 week ago Pondering Big Cosmology Questions Through Lectures and Dialogues View the latest post Replies 35 Views 62600
- by Eli 1 week ago The U.S - China Rivalry, Taiwan and Hong Kong View the latest post Replies 1 Views 557
-
How to store file path to MySQL database and files to a folder using PHP
-
- Information
-
Who is online
Users browsing this forum: No registered users and 1 guest