每当我尝试将带有图像的数据插入我的数据库时,图像都不会提交或保存。它只给出这样的 [BLOB-0B] 但数据(文本)已成功保存。
外部.php
class Dbother {
private $host = 'localhost';
private $user = 'root';
private $password = '';
private $dbname = 'pcnl';
private $conn = '';
function connect() {
$this->conn = mysql_connect($this->host, $this->user, $this->password) or die (mysql_error());
mysql_select_db($this->dbname, $this->conn) or die(mysql_error());
}
function addEvent($title, $place, $date, $people, $content, $eventImg, $EventExt) {
$sql = "insert into tbl_event values('$title', '$place', '$date', '$people', '$content', null, null, '$eventImg', '$EventExt', null)";
mysql_query($sql) or die (mysql_error());
mysql_close();
}
}
事件.php
<?php
require_once 'dbother.php';
$object = new Dbother();
$object->connect();
if(isset($_POST['title'])){
$title = $_POST['title'];
$place = $_POST['place'];
$date = $_POST['date'];
$people = $_POST['people'];
$content = $_POST['content'];
$eventImg=file_get_contents($_FILES['pic']['tmp_name']);
$eventImg=mysql_escape_string($eventImg);
@list(, , $imtype, ) = getimagesize($_FILES['pic']['tmp_name']);
if ($imtype == 3){
$EventExt="png";
}elseif ($imtype == 2){
$EventExt="jpeg";
}elseif ($imtype == 1){
$EventExt="gif";
}
$object->addEvent($title, $place, $date, $people, $content, $eventImg, $EventExt);
header('Location: events.php');
exit;
}
?>
<div>
<h4>New Event</h4>
<form name="eventform" id="eventform" method="post" action="events.php">
<p> Title: <input type="text" name="title" id="title" required pattern="[A-Za-z0-9 ,.)(*!?|<>:]{5,80}" title="Please enter valid title of you event."/></p>
<p> Where: <input type="text" name="place" id="place" required pattern="[A-Za-z0-9 ,.)(*!?|<>:]{5,100}"/></p>
<p>When: <input type="date" name="date" id="date" width="40px;" required /></p>
<p>People Involved: <input type="text" name="people" id="people" required/></p>
<p>Content:</p>
<textarea rows="4" cols="50" required name="content"></textarea>
<p><input type="file" name="pic" id="file" style="float:left">
<a href ="events.php"><input name="btnexit" type="button" id="btnexit" value="Cancel" style="width:80px; height:30px; margin:5px; border:2px solid #757575; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; float:right"></a>
<input name="btnfinish" type="submit" class="btnfinish" value="Done" style="width:80px; height:30px; margin:5px; border:2px solid #757575; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; float:right"></p>
</form>
抱歉,代码很长,希望您能帮助我。