Tuesday, 16 March 2010

Upload File

Make a table in advance to accommodate dafi information which you upload files.
Example:

Field

Type

Length

Extra

Primary

Id_upload

Int

3

Auto_increment

yes

Nama_file

Varchar

100



Ukuran

int

100



Deskripsi

text




Direktori

varcahr

100




Then make a special folder to hold files that will be uploaded.Such as folder files and the folder should be placed in the folder where you saved the web script.

Script from upload:


<form enctype="multipart/form-data" method="post" action="upload_1.php">
File yang diupload : <input type="file" name="fupload"><br>
Deskripsi File : <br><textarea name="deskripsi" rows="8" cols="40"></textarea><br>
<input type=submit value=Upload>
</form>



Script upload_1.php

// Read variable location, name & size of the file of the form (fupload)

$lokasi_file = $_FILES['fupload']['tmp_name'];

$nama_file = $_FILES['fupload']['name'];

$ukuran_file = $_FILES['fupload']['size'];

$direktori = "files/$nama_file";

//If the file successfully uploads

if (move_uploaded_file($lokasi_file,"$direktori")){

echo "Nama File : $nama_file berhasil di upload
";

echo "Ukuran File : $ukuran_file bytes";

// Masukkan informasi file ke database

mysql_connect("localhost","root","pajarmaning");

mysql_select_db("db_web");

// Enter information into the database file

$input="INSERT INTO upload_file(nama_file,ukuran_file,deskripsi,direktori)

VALUES('$nama_file','$ukuran_file','$_POST[deskripsi]','$direktori')";

mysql_query($input);

}

else{

echo "File gagal diupload";

}

?>

Description:
To keep in mind when sending a file is of the form method should be POST and add enctype = "multipartform / form_data" which implies that there are files that come included in the data transmission.

Move_uploaded_file (file_sumber, file_tujuan) is a function to upload a file.There is also a function copy (file_sumber, file_tujian) and the same function is to upload a file / copy file.

Test:

Click browse to select the file and click upload to upload a file.To ensure the file has been sent will be visible in the folder where you hold the files that have been made previously

Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments: on "Upload File"

Post a Comment

Terima kasih atas kunjungan anda