$target_path = "./upload/";
$target_path = $target_path . basename( $_FILES['myfile']['name']);
if(move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) //Upload file to target path
{
$fileName = $_FILES['myfile']['name']; // Get Filename
$fileSize = $_FILES['myfile']['size']; // Get filesize
$fileType = $_FILES['myfile']['type']; // Get filetype
echo "The picture ". basename( $_FILES['myfile']['name']) . " was uploaded successfully.";} else{
echo "There was an error uploading the file, please try again!";
}
像这样的东西。
mysql_query("INSERT INTO `files`(`title`, `filename`, `size`, `type`, `categorie`) VALUES ('$_POST[title]', '$fileName', '$fileSize', '$fileType', '$_POST[type]');");
这将是您所需要的。文件的上传 - 并为您的数据库添加额外的插入(文件名、大小等......)。
编辑:添加其他:错误消息和评论
编辑2:不要忘记:
<form action="" enctype="multipart/form-data" method="post">
和:
<input type="file" name="myfile">