Jump to content

Upload File To Directory


sildona

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.