-1

试图检查文件是否已经存在但它不起作用第 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>";
} 
}
4

1 回答 1

0

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

确保您的开场报价与结束报价相匹配。例如,有效字符串是"this"and 'this'

echo $_FILES['userfile']['name'] . " already exists. ";
echo $_FILES["userfile"]["name"] . " already exists. ";
// etc.
于 2012-10-16T04:41:35.403 回答