You basically need the following; please google for a more complete example, and/or the PHP manual pages (whichever you prefer):
1. HTML:
Code:
<form enctype="multipart/form-data" action="myupload.php" method="post">
...
<input type="file" name="myfile">
...
2. PHP:
Code:
<?php
// $userfile: where the file went on the web server
$userfile = $HTTP_POST_FILES['myfile']['tmp_name'];
// $userfile_name: the original file name
$userfile_name = $HTTP_POST_FILES['myfile']['name'];
// $userfile_size: the file size (bytes)
$userfile_name = $HTTP_POST_FILES['myfile']['size'];
...
3. mySQL:
Code:
sub insert
{
# Insert a new attachment into the database.
# Escape characters in strings that will be used in SQL statements.
my $filename = SqlQuote($::FILE{'data'}->{'filename'});
my $description = SqlQuote($::FORM{'description'});
my $contenttype = SqlQuote($::FORM{'contenttype'});
my $thedata = SqlQuote($::FORM{'data'});
# Insert the attachment into the database.
SendSQL("INSERT INTO attachments (bug_id, filename, description, mimetype,
ispatch, submitter_id, thedata)
VALUES ($::FORM{'bugid'}, $filename, $description, $contenttype,
$::FORM{'ispatch'}, $::userid, $thedata)");
# Retrieve the ID of the newly created attachment record.
SendSQL("SELECT LAST_INSERT_ID()");
my $attachid = FetchOneColumn();
The above is (in part) from "PHP and MySQL Web Development", Welling/Thomson, New Riders - highly recommended, and in part from Bugzilla (an open-source database that uses Perl - not PHP - and mySQL) "attachments.cgi".