我正在尝试上传图像并将其存储在数据库中。我已经提到了代码,但它对我不起作用。我无法找到错误。看看有没有人能找到bug。代码是:
<?php
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
if($_REQUEST['submit'])
{
if(($_FILES['file']['type']=="image/jpeg" or $_FILES['file']['type']=="image/pjpeg" or $_FILES['file']['type']=="image/gif") and ($_FILES['file']['size']<300000))
{
if($_FILES['file']['error']>0)
{
$err=" ERROR :: ".$_FILES['file']['error'];
}
else
{
echo "Upload :".$_FILES['file']['name']."<br/>";
echo "Type: ".$_FILES['file']['type']."<br/>";
echo "Size: ".($_FILES['file']['size']/1024)."Kb<br/>";
echo "Stored in: ".$_FILES['file']['tmp_name']."<br/>";
move_uploaded_file($_FILES['file']['tmp_name'],"upload/".$_FILES['file']['name']);
echo $_FILES['file']['name'];
echo $_FILES['file']['tmp_name']."qwerty";
$n=3000;
$fo=fopen("upload/".$_FILES['file']['name'],"r");
$fr=fread($fo,$n);
mysql_query("update user set pic='$fr' where id='$id'");
}
}
else
{
$err=" ERROR :: Invalid Image";
}
mysql_query("update user set name='$name' where id='$id'");
mysql_query("update user set email='$email' where id='$id'");
}
$sql="select * from user where id='$id'";
$con=mysql_query($sql);
list($idR,$nameR,$emailR,$pwdR,$dateR,$picR)=mysql_fetch_array($con);
?>
<body>
<form action="" method="post" enctype="multipart/form-data">
<table>
<tr>
<td colspan="2"><?php echo $err; ?></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name" value="<?php echo $nameR ?>" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" value="<?php echo $emailR ?>" /></td>
</tr>
<tr>
<td><label for="file">Upload or Change Pic:</label></td>
<td><input type="file" name="file" id="file" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Save"/></td>
</tr>
</table>
</form>
</body>
我的代码甚至无法上传文件。当我尝试echo
以下操作时,我发现它们是空的:
echo "Name:".$_FILES['file']['name']."<br/>";
echo "Type: ".$_FILES['file']['type']."<br/>";
echo "Size: ".($_FILES['file']['size']/1024)."Kb<br/>";
echo "Stored in: ".$_FILES['file']['tmp_name'];
以上所有字段均为空。