I wrote this script which probably will be usefull for You...
Have fun
<FORM ENCTYPE=multipart/form-data ACTION="yourpage.php" METHOD=post>
<input type=hidden name=MAX_FILE_SIZE value=1000000>
<INPUT NAME=userfile TYPE=file>
<input type=submit value="upload" name="addpic">
if ($addpic) {
// what is the doctype?
if (!file_exists($userfile) || $userfile_size==0) {
$serr="File $userfile doesn't exsist)";
}
// file is ok! lets move on
else {
switch (strtolower($userfile_type)) {
case "image/jpeg":
case "image/pjpeg":
$doctype="JPG"; break;
case "image/gif":
$doctype="GIF"; break;
case "audio/mpeg":
$doctype="MP3"; break;
case "audio/wav":
$doctype="WAV"; break;
case "video/avi":
$doctype="AVI"; break;
default:
$serr="Filetype $userfile_type invalid! (jpg,gif,wav,mp3,mpeg,avi are allowed)";
}
}
if ($serr=="") {
// lets make room for the new file
$editstmt = "insert into media " // or whatever your db table is called
. "set url = 'NEW'";
mysql_query($editstmt);
$query = "select id from media where url = 'NEW' ";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){
$mediaid="$row[id]";
}
// lets make an url for the file
$url="/pix/upl/$mediaid.".strtolower($doctype);
// copy the file
if (copy($userfile,'-----documentroot-----'.$url)) {
unlink($userfile); }
}