日期:2014-05-16 浏览次数:20525 次
<html>
<body>
<form action="upload.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>
</body>
</html>
<?php
if ($_FILES ['file'] != "none" && $_FILES ['file'] != "")
{
$time_limit = 60;
set_time_limit ( $time_limit );
$file_type = $_FILES ['file'] ['type'];
$file_name = $_FILES ['file'] ['name'];
$file_size = $_FILES ['file'] ['size'];
$fp = fopen ( $_FILES ['file'] ['tmp_name'], "rb" );
if (! $fp)
{
die ( "file open error" );
}
$file_data = file_get_contents($_FILES["file"]['tmp_name']);
//$file_data = fread($fp, $file_size ) ;
fclose ( $fp );
$conn = mysqli_connect ( "localhost", "root", "root" );
if (! $conn)
{
die ( "error : mysql connect failed" );
}
mysqli_select_db($conn,"onlytest" );
$sql = "insert into onlytest.file (contents,type,name,size) values ('$file_data','$file_type','$file_name','$file_size')";
$result = mysqli_query ($conn, $sql);
//$id = mysqli_insert_id ($conn);
//echo $id;
mysqli_close ( $conn );
set_time_limit ( 30 );
if ($result)
echo "succeed to upload the files ";
else
echo "failed!";
}
else
{
echo "You haven't uploaded any files!";
}
?>