Upload Image

function upImage($namaGambar, $gambar, $ukuran, $name) { list($nama, $ekstensi) = preg_split ('/[\.]+/', $gambar); //jika file= jpg/jpeg/png dan ukurannya < 1 mb if ( (strtolower($ekstensi) == "jpg" OR strtolower ($ekstensi) == "jpeg" OR strtolower($ekstensi) == "jpg/jpeg" OR strtolower($ekstensi) == "png") AND $ukuran<=1024) { $uploaddir = 'img-to/'; //direktori uploadnya $uploadfile = $uploaddir.$gambar; if (move_uploaded_file($_FILES[$name]['tmp_name'], $uploadfile)) { rename($uploaddir.$gambar."", $uploaddir.$namaGambar.".".$ekstensi.""); $file_new = $uploaddir.$namaGambar.".".$ekstensi; chmod ($uploaddir.$file_new."", 0777); return $file_new; } }else{ echo '<script>alert("Gambar terlalu besar, maksimal 1mb.");</script>'; return "-"; } }
Fungsi untuk upload ,

cara memanggil :

$wkt=date('dmYHis');

$nama_file=$wkt;
$file=$_FILES['gambar']['name'];
$size=$_FILES['gambar']['size']/1024;
if ($file<>""){
$gbr = upImage($nama_file, $file, $size, "gambar");
}

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.