将文件上传到数据库

时间:2016-01-14 16:51:20

标签: php mysql

我正在尝试将文件上传到我的数据库,但每次尝试都会给我一个Error Query Failed

我的代码如下:

<form method="post" action="" enctype="multipart/form-data">
  <div class="form-group">
    <label> Name of Institution/ School</label>
    <input class="form-control" name="institution">
  </div>
  <div class="form-group">
    <label>Graduating Year</label>
    <input class="form-control" name="graduate">
  </div>
  <div class="form-group"></div>
  <div class="form-group">
  <div class="form-group">
    <label>Upload Document</label>
    <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
    <input name="userfile" type="file" id="userfile">
  </div>
  <button type="submit" name="upload" value="upload" class="btn btn-primary">Add</button>
  
</form>

<?php

$institution =  $_POST['institution'];
$graduate =  $_POST['graduate'];
$userid = '12';

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}


//include 'library/config.php';
include('../config/hr_config.php');

$query = "INSERT INTO education (user_id, institution, graduate, name, size, type, content ) ".
"VALUES ('$userid', '$institution', '$graduate','$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed');
//include 'library/closedb.php';

echo "<br>File $fileName uploaded<br>";
}
?>

它不断给出错误,任何人都可以帮我看一下这个?

0 个答案:

没有答案