TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
karthika pommudu
NA
321
34.8k
cannot insert .pdf file to mysql db
Aug 5 2020 4:12 AM
Hi,
I tried to insert pdf file to database actually the file uploaded into the folder name 'upload ' but cannot insert into database.
Anyone can help me to clear this issue.
<div
class
=
"row"
>
<div
class
=
"col-xs-8 col-xs-offset-2 well"
>
<form method=
"post"
enctype=
"multipart/form-data"
>
<legend>Select File to Upload:</legend>
<div
class
=
"form-group"
>
<input type=
"file"
name=
"file1"
/>
</div>
<div
class
=
"form-group"
>
<input type=
"submit"
name=
"submit"
value=
"Upload"
class
=
"btn btn-info"
/>
</div>
</form>
</div>
</div>
if
(isset($_POST[
'submit'
]))
{
echo $filename = $_FILES[
'file1'
][
'name'
];
// destination of the file on the server
$destination =
'upload/'
. $filename;
// get the file extension
$extension = pathinfo($filename, PATHINFO_EXTENSION);
// the physical file on a temporary uploads directory on the server
$file = $_FILES[
'file1'
][
'tmp_name'
];
echo $size = $_FILES[
'file1'
][
'size'
];
if
(!in_array($extension, [
'pdf'
])) {
echo
"You file extension must be .pdf "
;
} elseif ($_FILES[
'myfile'
][
'size'
] > 1000000) {
// file shouldn't be larger than 1Megabyte
echo
"File too large!"
;
}
else
{
echo
'test'
;
// move the uploaded (temporary) file to the specified destination
if
(move_uploaded_file($file, $destination))
{
$sql =
"INSERT INTO files (id,filename,created) VALUES ('1','$filename', '1')"
;
if
(mysqli_query($link, $sql))
{
echo
"File uploaded successfully"
;
}
else
{
echo
'Failed to insiert the file.'
;
}
}
else
{
echo
"Failed to upload file."
;
}
}
}
Reply
Answers (
4
)
Warning: mysqli_query() expects at least 2 parameters, 1 is given in..
What is the problem with the code below? What will it output?