- <?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 20 hours ago Re: What is in Your Mind? View the latest post Replies 703 Views 299942
- by Eli 20 hours ago Russia Invades Ukraine View the latest post Replies 663 Views 235117
- by Eli 2 days ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 326 Views 34133
- by Eli 3 days ago PySpark for Large Data Processing View the latest post Replies 1 Views 6862
- by Eli 1 week ago President Museveni's Speech During International Development Association (IDA) Summit View the latest post Replies 1 Views 280
- by Eli 1 week ago From Simple Linear Regression Analysis to Covariance & Correlation to Independent Determinant, and R-Squared View the latest post Replies 11 Views 24837
- by Eli 1 week ago Collection of Greatest Christian Hymns of all Times View the latest post Replies 34 Views 67318
- by Eli 1 week ago Pondering Big Cosmology Questions Through Lectures and Dialogues View the latest post Replies 34 Views 58078
- by Eli 1 week ago Programmatically Manipulate Files: Renaming, Reading, Writing, Deleting, and Moving Files Between Folders View the latest post Replies 7 Views 15724
- by Eli 2 weeks ago Iran Launches Retaliatory Attack Against Israel, and Israel Retaliates by Attacking Iranian Isfahan Millitary Base View the latest post Replies 28 Views 17743
-
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