1
我收到img_description
,但我的img_name
保持空白。未收到图片上传
基本的PHP代码
$msg = "";
if(isset($_POST['upload'])) {
$target = "images/".basename($_FILES['image']['name']); // get error here
$image = $_FILES['image']['name']; // get error here
$text = $_POST['text'];
$sql = "INSERT into images (img_name, img_description) values ('$image', '$text')";
$smt = $heidisql->prepare($sql);
$smt->execute();
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) { //error here
$msg = "Image upload sucessfully";
}else {
$msg = "Image failed to upload properly";
}
我的基本形式
<form method="POST" action="checkout.php" enctype="multipart/form-date">
<input type="hidden" name="size" value="1000000">
<div>
<input type="file" name="image">
</div>
<div>
<textarea name="text" cols="40" rows="4" placeholder="img text decription" ></textarea>
</div>
<div>
<input type="submit" name="upload" value="upload img">
</div>
</form>
表:影像,属性 - > img_id,img_name,img_description
Error: Undefined index: image
你在表单标签的'enctype'中有一个拼写错误:'multipart/form-date' <=它应该是'multipart/form-data' –
你对[SQL注入](http:///php.net/manual/en/security.database.sql-injection.php),并且应该使用[Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)而不是串联你的查询。特别是因为你没有逃避用户输入! –
你的php.ini文件中有'file_uploads = On'吗? –