- <?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 2 days ago Re: What is in Your Mind? View the latest post Replies 689 Views 278899
- by Eli 4 days ago Iran Launches Retaliatory Attack Against Israel, and Israel Retaliates by Attacking Iranian Isfahan Millitary Base View the latest post Replies 28 Views 953
- by Eli 5 days ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 319 Views 13903
- by Eli 1 week ago Python Packages for Scientific Computing View the latest post Replies 8 Views 7391
- by Eli 1 week ago Dunia Yetu: Building Tanzania's Digital Future Together View the latest post Replies 5 Views 1904
- by Eli 1 week ago Russia Invades Ukraine View the latest post Replies 646 Views 215310
- by Eli 1 week ago Programmatically Move Files from One Folder to Another View the latest post Replies 6 Views 1458
- by Eli 2 weeks ago Collection of Greatest Christian Hymns of all Times View the latest post Replies 33 Views 48391
- by Eli 2 weeks ago What is Retrieval-Augmented Generation (RAG)? View the latest post Replies 2 Views 372
- by Eli 2 weeks ago Chat With ChatGPT - An Interactive Conversational AI View the latest post Replies 22 Views 29157
-
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 5 guests