Reputation: 11
I am trying to get image from user and save it in database, but it give this notice:
Notice : undefine index :u_pic in ...
<input type="file" name ="u_pic" class="file" style="margin-top: 10px;margin-left:10%;margin-right: 10%;width: 80%">
$image=addslashes(file_get_contents($_FILES['u_pic']['temp_name']));
$insert = "insert into users (profilepicture) values ('$image' )";
Upvotes: 0
Views: 293
Reputation: 957
You can get image name using $_FILES['u_pic']['name']
. You can get temp image name(location) using $_FILES['u_pic']['tmp_name']
.
You should use enctype='multipart/form-data
as a parameter in form tag. You should also use move_uploaded_file($_FILES['u_pic']['tmp_name'],$_FILES['u_pic']['name'])
php function to move file from temporary location to server.
Try to use move_uploaded_file function to move the file and store $_FILES['u_pic']['name']
as a filename in database table field.
Upvotes: 1