- 我希望能够在我的数据库中存储空文件。
- 我想将文件大小限制为 1mb。
我正在尝试上传带有和不带有文件的文件,但第一个if($_FILES['word']['size'] = (0000000))
不执行。相反,它执行 ELSE 语句,if($_FILES['word']['size'] < (1024000))
.
<?php
error_reporting(E_ALL ^ E_NOTICE);
mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("calendario") or die (mysql_error());
#Add Files in Database#
session_start();
if(isset($_POST['btnadd'])){
$title =$_POST['txttitle'];
$detail =$_POST['txtdetail'];
$month=$_POST['month'];
$day =$_POST['day'];
$year =$_POST['year'];
$eventdate = $month."/".$day."/".$year;
$emonth=$_POST['Emonth'];
$eday =$_POST['Eday'];
$eyear =$_POST['Eyear'];
$expire = $emonth."/".$eday."/".$eyear;
$code = $_SESSION['code'];
$id = $_SESSION["username"];
##############################################################################################Image
$word =$_FILES['word']['tmp_name'];
$word_name = addslashes($_FILES['word']['name']);
$word_size = addslashes($_FILES['word']['size']);
$word_type = $_FILES['word']['type'];
if($_FILES['word']['size'] = (0000000)) //if files uploaded empty, still enter database
{
echo("<script language=\"JavaScript\" type=\"text/JavaScript\">\n");
echo("alert('File Error 0.');\n");
echo("window.location = ('calender.php');\n");
echo("</script>\n");
}
else
{
if($_FILES['word']['size'] < (1024000)) //if files is less than 1mb
{
echo("<script language=\"JavaScript\" type=\"text/JavaScript\">\n");
echo("alert('File Error.');\n");
echo("window.location = ('calender.php');\n");
echo("</script>\n");
}
else{
$word = addslashes(file_get_contents($_FILES['word']['tmp_name']));
$word_name = addslashes($_FILES['word']['name']);
$word_size = addslashes($_FILES['word']['size']);
$fp = fopen($word, 'r');
$content = fread($fp, filesize($word));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$word_name = addslashes($word_name);
}
}
############################################################################################Insert
$sqlinsert = "INSERT into eventcalendar(classCode,Title,Detail,eventDate,dateAdded,Image,WordPpt,WordPptName,WordPptSize,WordPptType,Username,Edate) values ('".$code."','".$title."','".$detail."','".$eventdate."',now(),'".$image."','".$content."','".$word_name."','".$word_size."','".$word_type."','".$id."','".$expire."')";
$resultinginsert = mysql_query($sqlinsert);
}
if($resultinginsert){
echo("<script language=\"JavaScript\" type=\"text/JavaScript\">\n");
echo("alert('Done.');\n");
echo("window.location = ('calender.php');\n");
echo("</script>\n");
}else{
echo "(Event Failed to be Added....)";
}
}
else
{
echo "error";
}
?>