Pertemuan 10
Pertemuan 10
Pertemuan 10
PERTEMUAN-‐10
upload0
}
else
{
<?php
if(
$file_size
>
1048576
)
{
$status
=
"
if(
isset($_FILES["image"])
)
{
<script>
//
upload
file
alert('Ukuran
file
terlalu
besar');
//
file
apapun,
ukuran
berapapun
</script>
";
//
var_dump($_FILES);
die;
$file_name
=
$_FILES["image"]["name"];
}
else
{
$file_temp
=
$_FILES["image"]["tmp_name"];
if
(
move_uploaded_file($file_tmp,
"hasilupload/"
.
$file_name)
)
{
move_uploaded_file($file_temp,
"hasilupload/"
.
$status
=
"
$file_name);
<p>Image
Berhasil
Diupload</p>
echo
"file
berhasil
diupload";
<div
class='image'>
}
<img
src=\"hasilupload/$file_name\"/>
</div>
?>
";
<!doctype
html>
}
else
{
<html>
$status
=
"<p>image
gagal
diupload</p>";
<head>
}
<title>Upload
Image</title>
}
</head>
}
<body>
}
<form
action=""
method="post"
enctype="multipart/form-‐data">
?>
<label
for="image">
<!doctype
html>
<input
type="file"
name="image"
id="image">
<html>
</label>
<head>
<br>
<title>Upload
Image</title>
<input
type="submit"
name="submit"
value="upload">
<style>
p
{
color:
red;
font-‐style:
italic;
}
</form>
.image
img
{
width:
100px;
}
.image
{
</body>
width:
100px;
</html>
height:
100px;
overflow:
hidden;
}
upload1
</style>
<?php
</head>
<body>
if(
isset($_FILES["image"])
)
{
<div><?=
(
isset($status)
)
?
$status
:
"";
?></div>
<form
action=""
method="post"
enctype="multipart/form-‐data">
$extensions
=
array("jpg",
"jpeg",
"gif",
"png");
<label
for="image">
$file_name
=
$_FILES["image"]["name"];
<input
type="file"
name="image"
id="image">
$file_size
=
$_FILES["image"]["size"];
</label>
$file_tmp
=
$_FILES["image"]["tmp_name"];
<br>
$file_type
=
$_FILES["image"]["type"];
<input
type="submit"
name="submit"
value="upload">
$file_explode
=
explode(".",
$file_name);
</form>
$file_ext
=
strtolower(end($file_explode));
</body>
</html>
if(
($file_type
!=
"image/jpg")
||
($file_type
!=
"image/jpeg")
||
($file_type
!=
"image/gif")
||
($file_type
!=
"image/png")
&&
(!in_array($file_ext,
$extensions)
)
{
$status
=
"
<script>
alert('Jenis
file
salah,
harap
pilih
file
gambar');
</script>
";