2017-08-05 98 views
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

+1

你在表单标签的'enctype'中有一个拼写错误:'multipart/form-date' <=它应该是'multipart/form-data' –

+0

你对[SQL注入](http:///php.net/manual/en/security.database.sql-injection.php),并且应该使用[Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)而不是串联你的查询。特别是因为你没有逃避用户输入! –

+0

你的php.ini文件中有'file_uploads = On'吗? –

回答

1

你有一个错字您的表单标签中的enctype

变化

multipart/form-date 

multipart/form-data 
0

你有写错误ENCTYPE = “多部分/格式日期”使用ENCTYPE = “的multipart/form-data的”代替。