sildona Posted October 26, 2012 Share Posted October 26, 2012 Does anyone know of a PHP snippet of code that will 1. Obtain the file name off the file 2. Insert the file name into a database 3. upload the actual file to a directory I have the HTML form that sends the information, and I know how to connect to the database. I just need to know how to modify my PHP form processing file. Thanks for any leads! Link to comment https://forums.phpfreaks.com/topic/269939-upload-file-to-directory/ Share on other sites More sharing options...
MDCode Posted October 26, 2012 Share Posted October 26, 2012 <?php move_uploaded_file($_FILES["file"]["tmp_name"], "directory/" . $_FILES["file"]["name"]); ?> This will move the file itself, replace directory with your directory Adding to the database would be just with sql <?php $sql = "INSERT INTO `blah` (file) VALUES('$_FILES["file"]["tmp_name"]')"; ?> Sample form: <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> NOTE: Uploading requires a lot of security precautions. Do not just use my example to process your form and think that's it Link to comment https://forums.phpfreaks.com/topic/269939-upload-file-to-directory/#findComment-1387939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.