Upload a Picture to C# Unity Beginners

Uploading the image/videos into the database and display it using PHP is the way of uploading the image into the database and fetched it from the database. Using the PHP code, the user uploads the epitome or videos they are safely getting entry into the database and the images should be saved into a particular location past fetching these images from the database.
If any of the websites contain the functionality to upload images/videos with some detail, then by using this code nosotros will upload the prototype into your database and whether y'all would similar to ascertain what the person has got to be uploaded. And by this code the image which is uploaded that where salvage in your arrangement where you 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 image. The table contains ii fields:

  • Id – int(11)
  • Filename – VARCHAR(100)

Id should be in Auto incremented(AI). The paradigm of created database is shown below:

Plan: Now, we volition create a form for uploading images/videos files.

  • HTML code:

html

<!DOCTYPE html>

< html >

< head >

< championship >Paradigm Upload</ title >

< link rel = "stylesheet"

blazon = "text/css"

href = "manner.css" />

</ head >

< trunk >

< div id = "content" >

< form method = "Mail"

activity = ""

enctype = "multipart/form-data" >

< input type = "file"

proper name = "uploadfile"

value = "" />

< div >

< button type = "submit"

name = "upload" >

UPLOAD

</ button >

</ div >

</ form >

</ div >

</ trunk >

</ html >

  • CSS code: The fashion.css is the file that styles the form into a new pattern and the code is given below.

CSS

#content{

width : 50% ;

margin : 20px auto ;

border : 1px solid #cbcbcb ;

}

course{

width : 50% ;

margin : 20px auto ;

}

class div{

margin-superlative : 5px ;

}

#img_div{

width : 80% ;

padding : 5px ;

margin : 15px automobile ;

border : 1px solid #cbcbcb ;

}

#img_div:subsequently{

content : "" ;

display : block ;

clear : both ;

}

img{

float : left ;

margin : 5px ;

width : 300px ;

elevation : 140px ;

}

You tin can re-create the in a higher place code and mention it into the main lawmaking directly or create a link as same in the HTML code and attached with the main code which is given beneath. As mentioned that if yous 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 assist of POST method and the enctype="multipart/form-information is the action which encoding the files and allow you to sent through Postal service.
Now nosotros are work on the PHP code for the transfer of the paradigm from any binder of the system in a particular folder which you are mention and store information technology into the database as a directory.

  • PHP code: The PHP lawmaking is for the uploading images, the file name is saved with the index.php, y'all can also save with some other name as yous prefer.

php

<?php

error_reporting (0);

?>

<?php

$msg = "" ;

if (isset( $_POST [ 'upload' ])) {

$filename = $_FILES [ "uploadfile" ][ "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 , $folder ))  {

$msg = "Prototype 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 following:

  • The error_reporting(0) is for getting 0 error while php code is running.
  • $_files is work backside the scene. Information technology is existence used to upload files via the HTTP Postal service method and hold the attributes of files.
  • $filename is a name used to uniquely identify a computer 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 proper noun where the epitome is stored afterwards upload.
  • $folder defines the path of the uploaded image into the database to the folder where you desire to be stored. The "epitome/" the binder name where the image is to be saved subsequently the upload. And the .$filename is used for fetching or upload the file.
  • $db, the basic line for any of the PHP lawmaking for connecting to the database.
  • $sql used for the inserting the image into the database of table proper name epitome to the variable filename.
  • mysqli_query is the part to executing query of $db and $sql.
  • Now, let's move the uploaded image into the folder which named as the prototype. The epitome named folder is saved into the WAMP or XAMPP server folder which is in C drive into the www folder.
  • $outcome 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 every bit followed.

  • Program: File name: index.php This file combines the HTML and PHP code.

PHP

<?php

error_reporting (0);

?>

<?php

$msg = "" ;

if (isset( $_POST [ 'upload' ])) {

$filename = $_FILES [ "uploadfile" ][ "name" ];

$tempname = $_FILES [ "uploadfile" ][ "tmp_name" ];

$folder = "epitome/" . $filename ;

$db = mysqli_connect( "localhost" , "root" , "" , "photos" );

$sql = "INSERT INTO prototype (filename) VALUES ('$filename')" ;

mysqli_query( $db , $sql );

if (move_uploaded_file( $tempname , $folder ))  {

$msg = "Image uploaded successfully" ;

} else {

$msg = "Failed to upload image" ;

}

}

$effect = mysqli_query( $db , "SELECT * FROM paradigm" );

while ( $data = mysqli_fetch_array( $result ))

{

?>

<img src= "<?php echo $data['Filename']; ?>" >

<?php

}

?>

<!DOCTYPE html>

<html>

<head>

<title>Image Upload</title>

<link rel= "stylesheet" type= "text/css" href = "way.css" />

<div id= "content" >

<class method= "Mail" activeness= "" enctype= "multipart/grade-data" >

<input type= "file" name= "uploadfile" value= "" />

<div>

<push type= "submit" proper noun= "upload" >UPLOAD</button>

</div>

</class>

</div>

</body>

</html>

  • Output: Finally, you should upload the images, videos of less than 100 MB. If yous want to exceed more than change with the same.

Conclusion: The uploaded epitome into the database with the PHP code is having simple and using for diverse purposes. The code helps to upload the epitome so uploaded the image into the database and can be shown in another folder.
One affair you should note that when you are run this plan there should be a possibility that the image is not uploaded more than the two MB considering the PHP program has set the default value of uploading an image of 2 MB and mail the epitome of 8 MB. For exceeding the size of uploading the image you should follow the following steps:

  • Get-go, open the C drive, then open the folder WAMP or XAMPP server.
  • Then open up the bin folder.
  • Open up the PHP version binder (PHP v.half-dozen.31 folder) (KINDLY Note THAT IF Yous HAVE Some other VERSION OF PHP YOU SHOULD Open up THAT Too)
  • And so search php.ini. Open it and and so search the 2 variable and change with information technology. The variables are:
          upload_max_size = 100M post_max_filesize = 100M
  • Save with this change then open
C:\wamp64\bin\apache\apache2.4.27\bin
  • and search the php.ini. Change the same matter which are above mention.
  • Restart the WAMP or XAMPP server and and then run the code.

HTML is the foundation of webpages, is used for webpage evolution past structuring websites and web apps.You lot can learn HTML from the ground upward by following this HTML Tutorial and HTML Examples.

CSS is the foundation of webpages, is used for webpage development by styling websites and web apps.You can learn CSS from the footing up by following this CSS Tutorial and CSS Examples.

PHP is a server-side scripting linguistic communication designed specifically for web development. You can larn PHP from the ground up by following this PHP Tutorial and PHP Examples.


solomontuptionvill.blogspot.com

Source: https://www.geeksforgeeks.org/how-to-upload-image-into-database-and-display-it-using-php/

0 Response to "Upload a Picture to C# Unity Beginners"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel