* Sekilas Info


Pages: [1]
Print
Author Topic: Upload Single File pake PHP  (Read 181 times)
hyōrinmaru
Administrator
RPL Master
*****

Reputasi Anda: +4/-0
Posts: 430



View Profile WWW
« on: November 19, 2009, 10:55:16 AM »

ada syarat yang harus dipenuhi dalam pembuatan aplikasi ini adalah atribut folder/directory tempat untuk menampung hasil file yang telah di upload tidak boleh bertipe Read-Only. kalau anda mengUpload file ini ke server, maka directory pada server harus di ganti atributnya ke 777 (Choose Mode : 777) atau semua orang, baik user, admin, ataupun anonymous bisa memodifikasi folder ini.

untuk membuat aplikasi ini, anda kita butuh 2 file.
1. input.html ?> File input yang digunakan untuk memasukkan data2 file yang akan di upload.
2. upload.php ?> File yang akan anda isi dengan code untuk mengupload file dari input ke server.

1. input.html
Code:
<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="file" name="resource" /><br /&gt
<input type="submit" value="Upload" />
</form>

2. upload.php
Code:
<?php
$filename
=$_FILES['resource']['name'];
$directory="files/";
$upload=move_uploaded_file($_FILES['resource']['tmp_name'], $directory.$filename);
if($upload){
echo "$filename successfully added to server";
}
else{
echo "String Filename : ".$filename."<br>";
echo "Error while uploading file to server. Error Code : ".UPLOAD_ERR_OK;
}
?>


pada aplikasi upload.php, yang variabel superglobal yang kita gunakan adalah $_FILES. variabel superglobal jeni ini fungsingnya hanya sekedar untuk mengetahui layaknya properti sebuah file. misal nama file tersebut, error code yang terjadi pada saat upload file ke server, dsb.

fungsi yang digunakan disini adalah fungsi move_uploaded_file. fungsi inilah yang kita gunakan untuk memindah file ke server. fungsi ini memiliki nilai balik atau return value bertipe boolean yang berisi true atau false.

Download Link :
Code:
http://www.ziddu.com/download/7184465/uploadFile.zip.html

Keep Coding!

source : http://zhugo.co.cc/2009/11/upload-a-single-file-using-php/
« Last Edit: November 19, 2009, 09:06:51 PM by maznanda » Logged


Keep learning, 'till the end!
blo_b1
Administrator
Pro Member
*****

Reputasi Anda: +4/-2
Posts: 324



View Profile WWW
« Reply #1 on: November 20, 2009, 06:08:48 PM »

iyap mas,
tp caranya biar upload file nya lebih dr 2mb gmn??
aku lum mudeng...
Logged

YM: blo_b11/blo_b1
hyōrinmaru
Administrator
RPL Master
*****

Reputasi Anda: +4/-0
Posts: 430



View Profile WWW
« Reply #2 on: July 09, 2010, 03:18:23 PM »

iyap mas,
tp caranya biar upload file nya lebih dr 2mb gmn??
aku lum mudeng...
woo.. itu settingan ndek php.ini klw gak salah..
di setting aja.. max file size klo gak salah..
ganti ke 1GB.. hehe..
Logged


Keep learning, 'till the end!
lenz
Novice
**

Reputasi Anda: +0/-0
Posts: 87


WhY so SeriousE??


View Profile WWW
« Reply #3 on: July 30, 2010, 11:34:27 AM »

mas mau tanya, gimana klo multiple upload?????kayak di fb itu lo.....
Logged

Function callme() { echo "lenz"; }
blo_b1
Administrator
Pro Member
*****

Reputasi Anda: +4/-2
Posts: 324



View Profile WWW
« Reply #4 on: July 30, 2010, 02:44:01 PM »

mas mau tanya, gimana klo multiple upload?????kayak di fb itu lo.....

nti bisa nambah componen e to kang??
dlu mas sukko pernah post tentang add remove compnen html
Logged

YM: blo_b11/blo_b1
lenz
Novice
**

Reputasi Anda: +0/-0
Posts: 87


WhY so SeriousE??


View Profile WWW
« Reply #5 on: July 31, 2010, 12:51:36 PM »

mksudku gimana klo buat upload lebih dari 1 file.
Logged

Function callme() { echo "lenz"; }
blo_b1
Administrator
Pro Member
*****

Reputasi Anda: +4/-2
Posts: 324



View Profile WWW
« Reply #6 on: August 02, 2010, 11:56:01 AM »

ooow lek itu aku belum tw kang lenz,
lek tw nti kabar" yo kang??
Logged

YM: blo_b11/blo_b1
Pages: [1]
Print
 
Jump to: