如何检查数据库中是否已存在文件?

时间:2012-10-16 04:38:59

标签: mysql database file

尝试检查文件是否已经存在但是它不起作用LINE 6

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'];
if (file_exists($_FILES['userfile']['name']))
      {
      echo $_FILES['userfile"]["name'] . " already exists. ";
      }else{
$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 'library/opendb.php';

$query = "INSERT INTO upload (name, size, type, content )
VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

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

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

1 个答案:

答案 0 :(得分:0)

$_FILES['userfile"]["name']

确保您的开场报价与收盘报价相符。例如,有效字符串示例为"this"'this'

echo $_FILES['userfile']['name'] . " already exists. ";
echo $_FILES["userfile"]["name"] . " already exists. ";
// etc.