我的数据库中的所有内容都会填充,但实际图像本身除外。我已经看了好几个小时了,我似乎无法弄清楚为什么当我点击提交时我仍然会收到这些错误。虽然我得到错误的其他信息;大小,类型,名称确实显示在我的数据库中。请帮忙。这是我的代码。
<?php
ob_start();
?>
<?php
session_start();
if($_SESSION['nachos'] != "admin")
header("Location: index.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Steven Eck - Portfolio Form</title>
<style type="text/css">
.auto-style1 {
font-family: "Courier New", Courier, monospace;
font-size: x-large;
font-weight: bold;
}
.auto-style2 {
font-family: "Courier New", Courier, monospace;
font-weight: bold;
font-size: medium;
}
.auto-style3 {
font-family: "Courier New", Courier, monospace;
font-size: small;
text-decoration: blink;
}
</style>
</head>
<body style="color: #00FF00; background-color: #000000">
<div id="contentWrapper">
<div id="mainContent">
<?php
//display form if user has not clicked submit
if (!('POST' == $_SERVER['REQUEST_METHOD']))
{
?>
<form enctype="multipart/form-data" action="portfolioForm.php" method="post">
<fieldset>
<legend class="auto-style1">Project Information</legend>
<p><label for="txtTitle"><span class="auto-style2">Title</span>:</label>
<input type="text" name="txtTitle" id="txtTitle" ></p>
<p><span class="auto-style2"><label for="txtShortDescription">Short Description:</label></span>
<input type="text" name="txtShortDescription" id="txtShortDescription" ></p>
<p><span class="auto-style2"><label for="txtLongDescription">Long Description:</label></span>
<input type="text" name="txtLongDescription"id="txtLongDescription" ></p>
<p>
<input type="file" name="imgPhoto" id="imgPhoto" ></p>
<button type="submit">Submit</button>
<br><br><span class="auto-style3"><a href="index.php">Admin
Login</a></span><br class="auto-style3"><span class="auto-style3">
<a href="portfolioForm.php">Portfolio Form</a></span><br class="auto-style3">
<span class="auto-style3">
<a href="http://www.stevesays.net/newsite.php">Main Site</a></span><br>
<br><br><br><br><br>
</fieldset>
</form>
<?php
}
//the user has submitted the form
else
{
echo "<form><fieldset><legend>Project Information</legend>";
$dbConnection = mysqli_connect("lo***host", "we***stu_st***ck1", "r******aster", "w******u_351");
if(mysqli_connect_errno()){
echo '<p style="color: red;"> Failed to connect to MySql!: ' .mysqli_connect_error() . '</p>';
}
else
echo 'connected';
$handle = fopen($_FILES['imgPhoto']['tmpName'], "r");
$image = fread($handle, filesize($_FILES['imgPhoto']['tmpName']));
fclose($handle);
$image = mysqli_real_escape_string($dbConnection, $image);
mysqli_query($dbConnection, "INSERT INTO portfolio (title, shortDescription, longDescription, image, imageName, imageType, imageSize) VALUES ('$_POST[txtTitle]', '$_POST[txtShortDescription]', '$_POST[txtLongDescription]', '$image', '" . $_FILES['imgPhoto']['name']. " ', ' " . $_FILES['imgPhoto']['type']. " ', '" . $_FILES['imgPhoto']['size']. "' )");
echo "<p style=\"text-align: center; font-size: 11px;\">Thanks for filling out form!</p>";
echo "</fieldset></form>" ;
}
?>
</div>
这些是我得到的错误。虽然我仍然可以获取其他字段的数据,但是图像设置为blob并且它从不加载它。
警告:fopen()[function.fopen]:第100行/home/wequpstu/public_html/admin/portfolioForm.php中的文件名不能为空
警告:fread()要求参数1为资源,布线在第101行的/home/wequpstu/public_html/admin/portfolioForm.php中给出
警告:fclose()要求参数1为资源,第102行/home/wequpstu/public_html/admin/portfolioForm.php中给出布尔值
答案 0 :(得分:4)
错字错误tmpName
=&gt; tmp_name
$handle = fopen($_FILES['imgPhoto']['tmp_name'], "r");
$image = fread($handle, filesize($_FILES['imgPhoto']['tmp_name']));
答案 1 :(得分:1)
错误很明显:$ _FILES ['imgPhoto'] ['tmpName']在
中为空 $handle = fopen($_FILES['imgPhoto']['tmpName'], "r");