You are on page 1of 4

UPLOAD AND DOWNLOAD FILE

USING PHP SCRIPT AND SERVER PHPTRIAD


VIA FTP SERVER

Pada system komputerisasi yang menggunakan jaringan


sering kali kita diharuskan untuk melakukan proses upload
and download file yang ada pada file server. Untuk
melakukan hal tersebut ada beberapa konfigurasi yang dapat
dilakukan, diantaranya adalah konfigurasi phptriadnya
dengan cara :
1. Install PHPTRIAD sampai proses instalasi selesai.
2. Buka file php.ini pada folder c:/apache/php/php.ini.
Ubah baris post_max_size = 200M. Ini dimaksudkan agar
file yang dapat diupload bisa sebesar 200M.
3. Aktifkan server apache.

Untuk dapat mengupload dan mendownload file


menggunakan script php harus menggunakan syntax yang ada
pada php itu sendiri. Script – script itu sendiri saya
dapatkan pada web http://id2.php.net.
1. Untuk proses upload kita dapat menggunakan perintah
ftp_put, scriptnya adalah :
ftp_put ( resource $ftp_stream , string
$remote_file , string $local_file , int $mode [,
int $startpos ] )
Keterangan :
ftp_stream : The link identifier of the FTP
connection.
remote_file : The remote file path.
local_file : The local file path.
mode : The transfer mode. Must be either
FTP_ASCII or FTP_BINARY.
startpos

Contoh Script php :

<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';

// set up basic connection


$conn_id = ftp_connect($ftp_server);

// login with username and password


$login_result = ftp_login($conn_id, $ftp_user_name, $f
tp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII))
{
echo "successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}

// close the connection


ftp_close($conn_id);
?>
2. Untuk Proses Download saya menggunakan ftp_get,
sintaknya adalah :
ftp_get ( resource $ftp_stream , string
$local_file , string $remote_file , int $mode [,
int $resumepos ] )
Keterangan :

ftp_stream : The link identifier of the FTP


connection.
local_file : The local file path (will be
overwritten if the file already exists).
remote_file : The remote file path.
mode : The transfer mode. Must be either
FTP_ASCII or FTP_BINARY.
resumepos : The position in the remote file to
start downloading from.
Contoh Script PHP :
<?php

// define some variables


$local_file = 'local.zip';
$server_file = 'server.zip';

// set up basic connection


$conn_id = ftp_connect($ftp_server);

// login with username and password


$login_result = ftp_login($conn_id, $ftp_user_name, $f
tp_user_pass);

// try to download $server_file and save to $local_fil


e
if (ftp_get($conn_id, $local_file, $server_file, FTP_B
INARY)) {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}

// close the connection


ftp_close($conn_id);

?>

Untuk Lebih Jelasnya anda dapat mengunduh contoh


project yang telah saya kerjakan buat tugas kerja praktek
saya di Bulog Divre Jatim Surabaya di alamat
http://wahyu160585.net23.net

Biografi Penulis

Bambang Wahyu Saifudin. Saat artikel ini dibuat saya


masih kuliah di Institut Teknologi Adhi Tama Surabaya
(ITATS). Selama kuliah saya pernah mengikuti acara
undangan ke Jakarta untuk menghadiri undangan syuting
acara reality show “Negeri Impian” yang ditayangkan di
MetroTV.
Alamat E-mail : wahyu.gtg@gmail.com

You might also like