penjelasan script upload file menggunakan phpSeperti telah saya janjikan pada postingan sebelumnya, akan menjelaskan script dalam postingan tersebut. Berikut ini secara detail penjelasan dari tiap bagian penting dari script tersebut:

Scrip berikut ini berfungsi untuk menyiapkan halaman yang berisi form untuk melakukan upload

<form enctype=”multipart/form-data” action=”<? echo “$PHP_SELF”; ?>” method=”POST”>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”10000000″ />
</p>
<table width=”500″ border=”0″ cellspacing=”10″ cellpadding=”0″>
<tr>
<td width=”150″>Tugas</td>
<td><select name=”modul”>
<option value=”-” selected=”selected”>pilih…</option>
<option value=”Modul 4″>Modul 4</option>
<option value=”Modul 5″>Modul 5</option>
<option value=”Modul 6″>Modul 6</option>
<option value=”Modul 7″>Modul 7</option>
<option value=”Modul 8″>Modul 8</option>
<option value=”Modul 9″>Modul 9</option>
<option value=”Modul 11″>Modul 11</option>
</select></td>
</tr>
<tr>
<td width=”150″>File yang mau diupload</td>
<td><input name=”fileyangdiupload” type=”file” />&nbsp;
<input name=”upload” type=”submit” value=”upload” /></td>
</tr>
<tr>
<td colspan=”2″ align=”center”>&nbsp;</td>
</tr>
</table>

</form>

</body>
</html>

Sedangkan untuk script PHP berikut ini:

$modul = $_POST["modul"];
$tipefile = $_FILES["fileyangdiupload"]["type"];
$namafile = $_FILES["fileyangdiupload"]["name"];
$ukuranfile = $_FILES["fileyangdiupload"]["size"];
$tmpfile = $_FILES["fileyangdiupload"]["tmp_name"];
$err = $_FILES["fileyangdiupload"]["error"];

Script di atas berfungsi untuk menyimpan informasi file yang diupload ke dalam variabel sehingga dapat menyingkat dalam penulisan parameter dari file tersebut

if ( $tipefile == “application/vnd.openxmlformats-officedocument.wordprocessingml.document”
|| $tipefile == “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”
|| $tipefile == “application/vnd.openxmlformats-officedocument.presentationml.presentation”
|| $tipefile == “application/vnd.ms-powerpoint”
|| $tipefile == “application/vnd.ms-excel”
|| $tipefile == “application/msword”) {

Script di atas berfungsi menyaring tipe file yang diupload user, dalam hal ini saya membatasi user hanya bisa mengupload file MS Office (word, excell, dan powerpoint).

move_uploaded_file($tmpfile, $modul . “/” . $namafile);

Scrip diatas akan memindahkan file yang telah di upload dari folder temporary ke lokasi penyimpanan yang diinginkan


This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Leave a Reply

Categories
 
Translator
 
Indonesian flagEnglish flag     
 
Ads
 
Partners
 
  • what is my ip address?
  • Computer Blogs - Blog Catalog Blog Directory
  • Partner links
Follow Me
 
Connect to Me
 
Most Popular
Blogroll
 
Visitors
 
counter statistics
  since Dec 2009
Tags
 

Hosting No. 1 di Indonesia

©2009 Bahtiar.NET | Hanya seKedar Sebuah caTatan onLine | Valid XHTML | WordPress