Html文件:
<form action="cregister.php" method="post" enctype="multipart/form-data" class="form-horizontal" id="wizForm">
<input type="file" name="image" id="image" value="uploads/default.png" />
<button type="button" id="simple-post" class="btn btn-success submitBtn">Submit</button>
</form>
操作文件:
$filename = $_FILES['image']['name'];
$path = "uploads";
move_uploaded_file($_FILES['image']['tmp_name'], $path."/".$filename);
$photo = $path."/".$filename;
$insert = "INSERT INTO user (photo)VALUES ('$photo')";
$sth = $db->query($insert);
获取错误
Notice: Undefined index: image
答案 0 :(得分:2)
该文件不会以这种方式取值value="uploads/default.png"
<input type="file" name="image" id="image" value="uploads/default.png" />
您需要选择文件并提交表单
print_r($_FILES)
在行动档案中。
答案 1 :(得分:0)
试试这个
HTML
<html>
<form action="cregister.php" method="post" enctype="multipart/form-data" class="form-horizontal" id="wizForm">
<input type="file" name="image" id="image" value="uploads/default.png" />
<input type="submit" id="simple-post" class="btn btn-success submitBtn" value="Submit"/>
</form>
</html>
PHP
<?php
if(!empty($_FILES)){
print_r($_FILES);
$filename = $_FILES['image']['name'];
$path = "uploads";
move_uploaded_file($_FILES['image']['tmp_name'], $path."/".$filename);
$photo = $path."/".$filename;
}
?>