How to upload file using php

Page 1

How to Upload File Using PHP How to Upload File Using PHP - PHP, as server-side-scripting, is very possible to handle uploading files to the server. There are several things to note in uploading this file, namely: 1. In the HTML Form should be added attributes: ENCTYPE="multipart/form-data" 2. Input form upload file can use tag <input> with value attribute TYPE = "FILE". 3. To handle inputan, PHP provides a global array variable that is $_FILES. Index of these variables include:    

$_FILES['file']['name']: The original name of the uploaded file. $_FILES['file']['tmp_name']: The temporary name of the uploaded file. $_FILES['file']['size']: The size of the original file (in bytes). $_FILES['file']['type']: MIME file type uploaded.

4. Destination file upload folder should be writable (accessible), usually with permissions 777 or 775. For more details, here I give an example of its application to a php application program. Program 1 File Name: form_upload.php Description: The program displays file upload form. Type the following html code into notepad. <html> <head><title>Upload File</title></head> <body> <FORM ACTION="upload.php" METHOD="POST" ENCTYPE="multipart/form-data"> Upload File : <input type="file" name="file"><br> <input type="submit" name="Upload" value="Upload"> </FORM> </body> </html>

Html code Save the html code with the name form_upload.php in the htdocs folder. Program 2 File Name: upload.php Description: Program file upload process. Type the following php code into notepad. <?php if (isset($_POST['Upload'])) { $dir_upload = "images/"; $nama_file = $_FILES['file']['name'];


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.