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'嗎? –