basically you need an html form with an input field of type "file". php takes the file and puts it into a temp directory (see php.ini) when the form is submitted php automatically assigns the files handle to the name of the html input field you set in the html input, which in this case is: $thefile. Php will also set a variable to whatever the files name was on the client side. the variable name is always the same as the file handle plus "_name" so in this case its $thefile_name. the max file size attribute tells php not to accept any files larger then the specified size ( in bytes). I did the below code while writing this example so it iis not perfect. I would also change the name of the file to some serialized string to avoid overwriting files on your server, also, make sure php will have permission to write to the destination folder. You might also want to do some extra work like storing the size of the file into the database. You may also look into checking the files type, php will also initialize a variable with the content type of the passed in file, in our case: $thefile_type. This is not always reliable but can be usefull. I suggest staying awway from this method, also avoiding checking the files extension becuase on some platforms (MacOS) extensions are not used. The best method is to allow the user to select the type of file that is to be uploaded via a select box. if you are using a database which supports binary storage and you are only storing tiny files, you may want to look into storing the file directly into the database. Hope this has helped.
<!- Here is the html file -->
<form action="upload.php" method="POST" ENCTYPE="multipart/form-data">
<input type=file name=thefile>
<input type="hidden" name="MAX_FILE_SIZE" value="10000">
</form>
<!- Here is the php file: upload.php ->
if ($thefile)
{
mysql_query("insert into files (file_id,file_name) values ('NULL',$thefile_name");
copy ( $file, "path/to/where/to/keep/file/$thefile_name" );
}
else
{
echo "Please select a file to upload";