Upload File dan Pengelolaan File

Slides:



Advertisements
Presentasi serupa
PHP File Upload
Advertisements

Basic Issue In System Administration. Bassic Issue In System Administration Creating and managing accounts Performing administrative task Access control.
Database Android Dwi Muktianto
Pengantar Teknologi Mobile 8
Function.
Pemrograman Internet Mobile 7 PHP: Hypertext Preprocessors.
Alg&Pemrog 2B Sistem Komputer Variable  Variable dapat didefinisikan sebagai bagian dari memory untuk menyimpan nilai yang telah ditentukan.  Setiap.
Pemrograman Web Dasar-dasar PHP:  Pengantar PHP sebuah file PHP, PHP workings, PHP feathers, menjalankan PHP.  Sintaks Dasar PHP variable, operator,
Pengantar Teknologi Mobile 8
Internet Programming FORM DAN UP LOAD FILE M. Agus Zainuddin PENS – ITS Surabaya.
Pengantar PHP (Lanjutan)
Testing Implementasi Sistem Oleh :Rifiana Arief, SKom, MMSI
PRAKTIKUM 3 PEMROGRAMAN BASIS DATA. Menghapus baris  Deleting rows- DELETE FROM Use the DELELE FROM command to delete row(s) from a table, with the following.
Dasar Pemrograman Java Pertemuan 2 Pemrograman Berbasis Obyek.
METHOD, ARRAY DAN STRING
Simple Object Access Protocol
Matakuliah : T0016 / Algoritma dan Pemrograman Tahun : 2007 Versi : 6
Fungsi-fungsi tambahan dalam PHP Session dan Cookie
PHP By : Lisda Juliana P.,Ssi..
(HTML). Frames are most typically used to have a menu in one frame, and content in another frame. When someone clicks a link on the menu that web page.
Bayu Priyambadha, S.Kom.  PHP provide some functions to manage file, likes :  Open / Close  Write / Read  Add / append  Fopen = for open file  Fget.
Verb Tense Tense denotes the time of the action indicated by a verb. The time is not always the same as that indicated by the name of the tense.
1 Pertemuan 11 Function dari System Matakuliah: M0446/Analisa dan Perancangan Sistem Informasi Tahun: 2005 Versi: 0/0.
HOW TO ACHIEVE 30% BLENDED LEARNING IN 1 HOUR. Objective To achieve 30% blended learning To achieve 30% blended learning.
HTML Universitas Muhammadiyah Surakarta Yogiek Indra K.
F ORM Bayu Priyambadha, S.Kom. F ORM Form is the interface (user interface) for users to communicate with the application system. Each posted data from.
Chapter 10 – The Design of Feedback Control Systems PID Compensation Networks.
OPERATOR DAN FUNGSI MATEMATIK. Operator  Assignment operator Assignment operator (operator pengerjaan) menggunakan simbol titik dua diikuti oleh tanda.
Dasar query basis data dengan SQLite
Pemrogaman Web PHP.
Pemrograman WEB I Pertemuan 9.
PHP.
Pemasaran Berbasis Web
PHP: Hypertext Preprocessor
Pemrograman Web JavaScript
Teknik. Pemrog. Terstruktur 2
AJAX (Asynchronous Javascript And XML)
HTML BASIC (Contd…..) PERTEMUAN KEDUA.
Internet Programming PHP
CARA KERJA WEB Rofilde Hasudungan.
Pemrograman Berbasis Web
PHP Array & Form.
Pemrograman PHP Lanjut
AJAX Teguh S.
Pemasaran Berbasis web
Pemasaran Berbasis Web
Fungsi-fungsi tambahan dalam PHP Session dan Cookie
Kode Hamming.
PHP Fundamental Dhea Raniasti.
PHP (Array, File Handling)
Pemrograman Berorientasi Objek
Pemasaran Berbasis web
Pemrograman Basis Data Berbasis Web
Pemrograman Web HTML (7) PHP Andy Haryoko, ST
PERTEMUAN 9 PHP 2.
Pengantar PHP (Lanjutan)
ACCUMULATION PROBLEMS
© Mark E. Damon - All Rights Reserved Another Presentation © All rights Reserved
PHP (Array, File Handling)
Teknik. Pemrog. Terstruktur 2
Algoritma & Pemrograman 1 Achmad Fitro The Power of PowerPoint – thepopp.com Chapter 3.
Lesson 2-1 Conditional Statements 1 Lesson 2-1 Conditional Statements.
HughesNet was founded in 1971 and it is headquartered in Germantown, Maryland. It is a provider of satellite-based communications services. Hughesnet.
 Zoho Mail offers easy options to migrate data from G Suite or Gmail accounts. All s, contacts, and calendar or other important data can be imported.
Fix problems opening Norton  Fix problems opening Norton This problem can happen after you update Norton. To fix the matter, restart the computer. Fix.
If you are an user, then you know how spam affects your account. In this article, we tell you how you can control spam’s in your ZOHO.
How do I Add or Remove a delegate to my Gmail account? Google launched delegation service 9 years ago for Gmail that allows you to give permission to access.
In this article, you can learn about how to synchronize AOL Mail with third-party applications like Gmail, Outlook, and Window Live Mail, Thunderbird.
Teknik Komputer & Jaringan SMK Al-Muhtadin Sahadi, ST
Media Pembelajaran PATHWAY TO ENGLISH Kelompok Peminatan Untuk SMA/MA Kelas X.
Transcript presentasi:

Upload File dan Pengelolaan File

Upload File Upload merupakan proses penyalinan data yang ada dari komputer client ke komputer server. Faslilitas upload memungkinkan aplikasi web misalnya pendaftaran keanggotaan. Biasanya upload digunakan untuk mempermudah administrasi.

Handling File Uploads in PHP PHP must run with the right settings. You may need to change the PHP configuration file php.ini. A temporary storage directory must exists with the correct permissions. Uploaded files are stored here temporarily; the files may be removed from here when your PHP script finishes processing the HTTP request. The final storage directory must exists with the correct permissions. You have to write codes to move the uploaded files from the temporary directory to another directory.

Configuring php.ini file_uploads max_input_time post_max_size Enable/disable PHP support for file uploads max_input_time Indicates how long, in seconds, a PHP script is allowed to receive input post_max_size Size, in bytes, of the total allowed POST data upload_tmp_dir Indicates where uploaded files should be temporarily stored upload_max_filesize Size, in bytes, of the largest possible file upload allowed

File Upload Form upload.html: <html> <head><title>PHP File Upload Form</title></head> <body> <form enctype="multipart/form-data“ action="upload.php” method="post"> <input type="hidden" name="MAX_FILE_SIZE” value="1000000"> File:<input type="file" name="userfile"><br> <input type="submit" value="Upload"> </form> </body> </html>

Character Encoding of Form-Data <form enctype=“value”> The enctype attribute specifies how form-data should be encoded before sending it to the server. By default, form-data is encoded to "application/x-www-form-urlencoded”. This means that all characters are encoded before they are sent to the server Spaces are converted to "+" symbols Special characters are converted to ASCII HEX values).

Character Encoding <form enctype=“value”> Value Description application/x-www-form-urlencoded All characters are encoded before sent (default setting) multipart/form-data No characters are encoded. This value is required when you are using forms that have a file upload control text/plain Spaces are converted to "+" symbols Special characters are not encoded

File Upload Form Label is automatically assigned

Receiving files $_FILES['userfile']['tmp_name'] name of the temporary copy of the file stored on the server. $_FILES['userfile']['name'] name of uploaded file. $_FILES['userfile']['size'] size of the uploaded file (in bytes). $_FILES['userfile']['type'] MIME type of the file such as image/gif. $_FILES['userfile']['error'] error that may have been generated as a result of the upload.

Upload error check $userfile_error = $_FILES['userfile']['error']; if ($userfile_error > 0) { echo 'Problem: '; switch ($userfile_error){ case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; case 3: echo 'File only partially uploaded'; case 4: echo 'No file uploaded'; } exit; PHP.ini : upload_max_filesize = 2M HTML form : MAX_FILE_SIZE directive.

bool is_uploaded_file ( string $filename ) Returns TRUE if the file named by filename was uploaded via HTTP POST. This is useful to help ensure that a malicious user hasn't tried to trick the script into working on files upon which it should not be working --for instance, /etc/passwd.

bool move_uploaded_file ( string $filename , string $destination ) This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.

Move the uploaded file $tempfile = $_FILES['userfile']['tmp_name']; $userfile = $_FILES['userfile']['name']; // Destination file on server $destfile = '/var/www/html/a_______/temp' . $userfile; // Do we have an uploaded file? if (is_uploaded_file($tempfile)) { // Try and move uploaded file to local directory on server if (!move_uploaded_file($tempfile, $destfile)) { echo 'Problem: Could not move to destination directory'; exit; } else { echo 'Possible file upload attack. Filename: '. $userfile; echo 'File uploaded successfully<br /><br />'; Note: The target folder must exist for this example to work! See Upload.html, upload.php

Operasi File

Operasi File Secara umum format file dibedakan menjadi file teks (ASCII) dan file biner (binary). Contoh file teks adalah file-file dokumen HTML, termasuk didalamnya file script PHP, sedangkan file biner adalah file-file program atau file yang disimpan dalam format biner lainnya. Secara umum bekerja dengan file selalu mempunyai pola sebagai berikut : Buka file: Sintaks : $fhandle = fopen(”namafile”, ”mode”) Mode akses : r, r+, w, w+, a, a+, b (binary, agar tidak dibedakan sebagai teks atau biner). Proses File: Berisi perintah-perintah yang digunakan untuk melakukan pemrosesan file, bisa menulis ke file atau membaca data dari file. Menutup File: Sintaks : fclose ($fhandle)

Operasi File Membaca Data dari File fgets() :$var = fgets ($fhandle, jumlahdata) Membaca data file secara baris per baris string. Setiap baris ditandai dengan adanya karakter ganti baris (newline). Jumlah data digunakan untuk membatasi jumlah byte yang harus dibaca. fread() : $var = fread($fhandle, jumlahdata) Melakukan pembacaan file dalam mode binary dalam mode yang aman (safe mode) dengan jumlah data yang dibaca per sekali baca adalah jumlahdata. fgetc() : $var = fgetc($fhandle) Membaca data file per karakter (satu karakter satu karakter). Menulis ke File fwrite() : fwrite($fhandle,string,length) menulis dalam mode binary safe (binary dan character bisa digunakan).

Operasi File

Operasi File