Simple PHP Upload Form with Rename file.

By in Tutorial on July 13, 2016
Simple PHP Upload Form with Rename file

Simple PHP Upload Form with Rename file

 

Script PHP Uploader ini lengkap dengan CSS-nya, bagi yang membutuhkan “Simple PHP Upload Form with Rename file”, silahkan COPAS Kodenya.
Simple dan semoga bermanfaat, untuk CSS-nya dan Fungsi file uploadnya, silahkan di edit sendiri sesuai kebutuhan Anda.

KODE :

 

<?php
$sUploadDir = ‘upload/';
$allowtype = array(‘jpg’, ‘jpeg’, ‘png’, ‘gif’);
$name1 = $_POST[‘name1′];
?><!DOCTYPE html>
<html>
<head>
<title>Upload Files</title>
<style>
body { background:#fff; padding:20px; font-family:Arial; font-size:14px; color:#666; text-shadow:0 1px 2px #999; }
.x, .z { background:#eee; border:1px #333 solid; width:320px; height:30px; padding-left:10px; font-size:14px; color:#000; box-shadow:0px 0px 10px #333; }
.x:focus { background:#fff; box-shadow:0px 0px 10px #ff0000; }
.y { background:#060bf6; text-align:center; font-size:14px; color:#fff; font-weight:bold; width:90px; height:30px; border:1px #333 solid; box-shadow:0px 0px 4px #333; cursor:pointer; }
.y:hover { background:#fad000; color:#ff0000; text-shadow:0 1px 2px #666; }
</style>
</head>
<body><?php
if(isset($_FILES[‘picThumbnail’]) && strlen($_FILES[‘picThumbnail’][‘name’]) > 1)
{
$sUploadedFile = $sUploadDir . basename($_FILES[‘picThumbnail’][‘name’]);
$sepext = explode(‘.’, ($_FILES[‘picThumbnail’][‘name’]));
$type = end($sepext);
$err = ”;if(!in_array($type, $allowtype)) $err .= ‘File: <b>’. $_FILES[‘picThumbnail’][‘name’] .’ </b><font color=”red”>Tidak di izinkan</font>, Hanya file berextensi <b>jpg, jpeg, png, dan gif</b> yang diperbolehkan.<hr><br>';
if (empty($_POST[‘name1′]) ) $err .= ‘<font color=”red”>Nama baru untuk file yang di upload harus di isi</font><br>File: <b>’.$_FILES[‘picThumbnail’][‘name’].'</b><br><br><br><font color=”red”><i>Tidak di upload !</i></font><hr><br>';if($err == ”)
{

$sUploadedFile = $sUploadDir . basename($_FILES[‘picThumbnail’][‘name’]);
if (move_uploaded_file($_FILES[‘picThumbnail’][‘tmp_name’], $sUploadedFile))
{
$sThumbnail = $_FILES[‘picThumbnail’][‘name’];
$sThumbnail = $name1.”.”.$type;
$sFileName = ($sThumbnail);
if (file_exists(($sUploadDir.$_FILES[‘picThumbnail’][‘name’])))
rename(($sUploadDir.$_FILES[‘picThumbnail’][‘name’]), ($sUploadDir.$sFileName));
echo ‘Nama baru untuk file: <b>’.$_FILES[‘picThumbnail’][‘name’].'</b> adalah:<br>';
echo ‘<b>’.$sFileName.'</b><br><br><font color=”green”><i>Telah sukses di upload !</font></i><hr><br>';
}

}
else echo $err;
}
?>

<form method=”post” enctype=”multipart/form-data” action=””>
<strong>Pilih berkas gambar untuk di upload :</strong>
<br><br>
<input type=”file” name=”picThumbnail” class=”z”>
<br><br>
<strong>Nama baru untuk file yang di upload :</strong> <sup><font color=”red” size=”1″>Wajib di isi</font></sup>
<br><br>
<input type=”text” name=”name1″ id=”name1″ class=”x” placeholder=”Contoh : File saya” maxlength=”14″>
<br><br>
<input type=”submit” value=”UPLOAD” class=”y”>
</form>
<p>&nbsp;</p>

</body>
</html>

 

Download filenya dalam bentuk “RAR” di link bawah ini :
Simple PHP Upload Form with Rename file.

Simpan File diatas dengan nama “index.php”, dan buatlah bolder baru dengan nama “upload” lalu Upload keserver Anda, dalam satu folder.
Semoga bermanfaat, dan selamat mencoba.



Baca juga :

Bagikan ini ke :

Comments are closed.