- <?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 1 hour ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 323 Views 23220
- by Eli 1 day ago Re: What is in Your Mind? View the latest post Replies 697 Views 288291
- by Eli 1 day ago Russia Invades Ukraine View the latest post Replies 655 Views 224095
- by Eli 2 days ago Collection of Greatest Christian Hymns of all Times View the latest post Replies 34 Views 57089
- by Eli 3 days ago Pondering Big Cosmology Questions Through Lectures and Dialogues View the latest post Replies 34 Views 57572
- by Eli 4 days ago Programmatically Manipulate Files: Renaming, Reading, Writing, Deleting, and Moving Files Between Folders View the latest post Replies 7 Views 6171
- by Eli 1 week ago Iran Launches Retaliatory Attack Against Israel, and Israel Retaliates by Attacking Iranian Isfahan Millitary Base View the latest post Replies 28 Views 5697
- by Eli 2 weeks ago Python Packages for Scientific Computing View the latest post Replies 8 Views 12381
- by Eli 2 weeks ago Dunia Yetu: Building Tanzania's Digital Future Together View the latest post Replies 5 Views 3181
- by Eli 3 weeks ago What is Retrieval-Augmented Generation (RAG)? View the latest post Replies 2 Views 4911
-
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 0 guests