为什么我不能把我的pdf块放到mysql数据库中?

时间:2012-05-23 01:53:03

标签: php mysql pdf upload

所以,这是我试图用来将一个大的pdf文件分解成块并将其存储在我的数据库中的代码。它有什么理由不起作用吗?我整天都在努力解决这个问题并且已经成功了。非常感谢任何帮助!谢谢!

<?
$username="something";
$password="something";
$database="something";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");

$STARTFILE = 1;
$ONFILE = "file" . $STARTFILE;

while (isset($HTTP_POST_FILES["$ONFILE"])) {

// Try!
$SrcPathFile = $HTTP_POST_FILES["$ONFILE"]["tmp_name"];
$SrcFileType = $HTTP_POST_FILES["$ONFILE"]["type"];
$DstFileName = $HTTP_POST_FILES["$ONFILE"]["name"];

clearstatcache();
$time = filemtime($SrcPathFile);
$storedate = date("Y-m-d H:i:s", $time);

// File Processing
if (file_exists($SrcPathFile)) {

// Insert into file table
$SQL  = "insert into tbldocuments(Type,Description,Size,DateTime) values ('";
$SQL .= $SrcFileType . "', '" . $DstFileName . "', " . filesize($SrcPathFile);
$SQL .= ", '" . $storedate . "')";

if (!$RES = mysql_query($SQL, $linkid)) {
  die("Failure on insert to file table!");
}

$fileid = mysql_insert_id($linkid);

// Insert into the filedata table
$fp = fopen($SrcPathFile, "rb");
while (!feof($fp)) {

  // Make the data mysql insert safe
  $binarydata = addslashes(fread($fp, 65535));

  $SQL = "insert into tblDocumentChunks (documentId,chunkData) values (";
  $SQL .= $fileid . ", '" . $binarydata . "')";

  if (!mysql_query($SQL, $linkid)) {
    die("Failure to insert binary inode data row!");
  }
}

fclose($fp);
}

$STARTFILE ++;
$ONFILE = "file" . $STARTFILE;
}

echo "Upload Complete";
?>

1 个答案:

答案 0 :(得分:0)

首先,$HTTP_POST_FILES已被弃用了很长一段时间。请改用$_FILES

其次,您声明了一个变量$ONFILE,但您没有在数组中引用它。

尝试删除引号($ONFILE而不是"$ONFILE"