how do you upload videos onto math counts website how do you upload videos onto mathcounts website
Uploading the image/videos into the database and display it using PHP is the manner of uploading the image into the database and fetched it from the database. Using the PHP lawmaking, the user uploads the image or videos they are safely getting entry into the database and the images should be saved into a detail location by fetching these images from the database.
If any of the websites contain the functionality to upload images/videos with some particular, and so past using this code we will upload the image into your database and whether you would like to ascertain what the person has got to be uploaded. And by this code the image which is uploaded that where save in your system where you lot are given the location.
First, create the database on XAMPP/WAMP server using phpMyAdmin and give the database name is photos and the table proper name is epitome. The tabular array contains ii fields:
- Id – int(eleven)
- Filename – VARCHAR(100)
Id should be in Car incremented(AI). The image of created database is shown below:
Program: Now, we will create a course for uploading images/videos files.
- HTML code:
html
<!DOCTYPE html>
<
html
>
<
head
>
<
championship
>Image Upload</
title
>
<
link
rel
=
"stylesheet"
type
=
"text/css"
href
=
"style.css"
/>
</
head
>
<
body
>
<
div
id
=
"content"
>
<
form
method
=
"Postal service"
activity
=
""
enctype
=
"multipart/form-information"
>
<
input
type
=
"file"
name
=
"uploadfile"
value
=
""
/>
<
div
>
<
button
blazon
=
"submit"
proper noun
=
"upload"
>
UPLOAD
</
button
>
</
div
>
</
course
>
</
div
>
</
torso
>
</
html
>
- CSS code: The style.css is the file that styles the form into a new design and the lawmaking is given below.
CSS
#content{
width
:
fifty%
;
margin
:
20px
auto
;
border
:
1px
solid
#cbcbcb
;
}
course{
width
:
50%
;
margin
:
20px
car
;
}
form div{
margin-elevation
:
5px
;
}
#img_div{
width
:
fourscore%
;
padding
:
5px
;
margin
:
15px
auto
;
edge
:
1px
solid
#cbcbcb
;
}
#img_div:after{
content
:
""
;
display
:
block
;
clear
:
both
;
}
img{
float
:
left
;
margin
:
5px
;
width
:
300px
;
peak
:
140px
;
}
Y'all tin copy the above code and mention information technology into the main code directly or create a link as same in the HTML code and fastened with the main lawmaking which is given below. Every bit mentioned that if you link the stylesheet file you should create another file in .css format and saved information technology on the place where the main file to be saved. The form created with the help of POST method and the enctype="multipart/grade-information is the action which encoding the files and allow y'all to sent through POST.
Now nosotros are work on the PHP lawmaking for the transfer of the image from any folder of the system in a particular folder which you are mention and store it into the database as a directory.
- PHP code: The PHP code is for the uploading images, the file name is saved with the alphabetize.php, y'all can also save with another proper noun every bit you prefer.
php
<?php
error_reporting
(0);
?>
<?php
$msg
=
""
;
if
(isset(
$_POST
[
'upload'
])) {
$filename
=
$_FILES
[
"uploadfile"
][
"name"
];
$tempname
=
$_FILES
[
"uploadfile"
][
"tmp_name"
];
$binder
=
"image/"
.
$filename
;
$db
= mysqli_connect(
"localhost"
,
"root"
,
""
,
"photos"
);
$sql
=
"INSERT INTO image (filename) VALUES ('$filename')"
;
mysqli_query(
$db
,
$sql
);
if
(move_uploaded_file(
$tempname
,
$folder
)) {
$msg
=
"Image uploaded successfully"
;
}
else
{
$msg
=
"Failed to upload image"
;
}
}
$result
= mysqli_query(
$db
,
"SELECT * FROM image"
);
?>
Explanation: The following are the explanation to create the PHP code which is the post-obit:
- The error_reporting(0) is for getting 0 mistake while php lawmaking is running.
- $_files is work backside the scene. It is being used to upload files via the HTTP POST method and hold the attributes of files.
- $filename is a name used to uniquely place a estimator file stored in a file system.
- $tempname is used to re-create the original name of the file which is uploaded to the database every bit the temp name where the prototype is stored subsequently upload.
- $binder defines the path of the uploaded image into the database to the folder where yous want to be stored. The "image/" the folder name where the paradigm is to be saved after the upload. And the .$filename is used for fetching or upload the file.
- $db, the bones line for whatever of the PHP code for connecting to the database.
- $sql used for the inserting the image into the database of table proper name image to the variable filename.
- mysqli_query is the function to executing query of $db and $sql.
- Now, let's move the uploaded epitome into the binder which named as the image. The image named folder is saved into the WAMP or XAMPP server folder which is in C drive into the world wide web folder.
- $result function is used for the retrieve the image from the database.
Combination of the above codes: And the final code of upload the image into MySQL using PHP is as followed.
- Program: File name: alphabetize.php This file combines the HTML and PHP code.
PHP
<?php
error_reporting
(0);
?>
<?php
$msg
=
""
;
if
(isset(
$_POST
[
'upload'
])) {
$filename
=
$_FILES
[
"uploadfile"
][
"proper name"
];
$tempname
=
$_FILES
[
"uploadfile"
][
"tmp_name"
];
$folder
=
"image/"
.
$filename
;
$db
= mysqli_connect(
"localhost"
,
"root"
,
""
,
"photos"
);
$sql
=
"INSERT INTO image (filename) VALUES ('$filename')"
;
mysqli_query(
$db
,
$sql
);
if
(move_uploaded_file(
$tempname
,
$binder
)) {
$msg
=
"Image uploaded successfully"
;
}
else
{
$msg
=
"Failed to upload epitome"
;
}
}
$upshot
= mysqli_query(
$db
,
"SELECT * FROM image"
);
while
(
$data
= mysqli_fetch_array(
$result
))
{
?>
<img src=
"<?php echo $data['Filename']; ?>"
>
<?php
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Prototype Upload</title>
<link rel=
"stylesheet"
type=
"text/css"
href =
"style.css"
/>
<div id=
"content"
>
<class method=
"Post"
action=
""
enctype=
"multipart/class-information"
>
<input type=
"file"
name=
"uploadfile"
value=
""
/>
<div>
<button type=
"submit"
name=
"upload"
>UPLOAD</push>
</div>
</form>
</div>
</body>
</html>
- Output: Finally, you lot should upload the images, videos of less than 100 MB. If you want to exceed more than than change with the same.
Conclusion: The uploaded image into the database with the PHP code is having elementary and using for diverse purposes. The lawmaking helps to upload the image and and so uploaded the epitome into the database and can exist shown in another binder.
One thing yous should note that when you are run this program there should be a possibility that the image is non uploaded more the 2 MB because the PHP programme has set the default value of uploading an image of 2 MB and mail the image of 8 MB. For exceeding the size of uploading the image you should follow the following steps:
- Kickoff, open the C drive, and then open up the folder WAMP or XAMPP server.
- And so open the bin binder.
- Open the PHP version folder (PHP 5.6.31 binder) (KINDLY NOTE THAT IF Y'all HAVE ANOTHER VERSION OF PHP YOU SHOULD OPEN THAT Also)
- And so search php.ini. Open it and so search the ii variable and change with information technology. The variables are:
upload_max_size = 100M post_max_filesize = 100M
- Salve with this modify and then open
C:\wamp64\bin\apache\apache2.4.27\bin
- and search the php.ini. Change the aforementioned thing which are higher up mention.
- Restart the WAMP or XAMPP server and so run the code.
HTML is the foundation of webpages, is used for webpage development past structuring websites and web apps.You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.
CSS is the foundation of webpages, is used for webpage development past styling websites and web apps.You can acquire CSS from the basis upwards by following this CSS Tutorial and CSS Examples.
PHP is a server-side scripting language designed specifically for web development. You tin can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.
edwardssuliterty1953.blogspot.com
Source: https://www.geeksforgeeks.org/how-to-upload-image-into-database-and-display-it-using-php/
0 Response to "how do you upload videos onto math counts website how do you upload videos onto mathcounts website"
Post a Comment