Script Sederhana Upload File

Dibawah ini adalah script Upload File ke server.

Kita akan memanfaatkan fungsi dalam php yang sudah ada yaitu move_uploaded_file, yang berfungsi untuk memindahkan file dari local komputer kita ke server.

Saya rasa upload file suatu saat diperlukan, misal untuk mengupload gambar atau file – file aplikasi lainnya.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Upload</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
</head>

<body>
<?php
$uploadDir = ‘./upload/’;
if(isset($_POST['upload'])):

$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath);

if (!$result):
echo “Error uploading file”;
exit;
else:
echo “upload sukses”.$filePath;
endif;

endif;

?>
<form action=”<?=$_SERVER['PHP_SELF']?>” method=”post” enctype=”multipart/form-data”>
<table width=”350″ border=”0″ cellpadding=”1″ cellspacing=”1″ class=”box”>
<tr>
<td width=”246″>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”5000000″>
<input name=”userfile” type=”file” id=”userfile”>
</td>
<td width=”80″><input name=”upload” type=”submit” class=”box” id=”upload” value=” Upload “></td>
</tr>
</table>
</form>
</body>
</html>

Tinggalkan Balasan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Ubah )

Twitter picture

You are commenting using your Twitter account. Log Out / Ubah )

Facebook photo

You are commenting using your Facebook account. Log Out / Ubah )

Connecting to %s

Ikuti

Get every new post delivered to your Inbox.