Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* PHP Script
- Upload Automatic Resize (Photo)
- Created By Wildan Izzudin.
- (c) 2018 Underxploit
- */
- error_reporting(0);
- // --- Function Resize Image --- //
- function resize($resource, $width, $height) {
- $new_width = 450; // New Width (px)
- $new_height = 450; // New Height (px)
- $new_layer = imagecreatetruecolor($new_width, $new_height); // New Layer
- imagecopyresampled($new_layer, $resource,0,0,0,0, $new_width, $new_height, $width, $height);
- return $new_layer;
- }
- // --- Function Random A-za-Z0-9 --- //
- function acakadut($jumlah) {
- $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz';
- $strs = '';
- for($i = 0; $i < $jumlah; $i++) {
- $pos = rand(0, strlen($str)-1);
- $strs .= $str{$pos};
- }
- return $strs;
- }
- if(isset($_POST["upload"])) {
- if(is_array($_FILES)) {
- $gambar = $_FILES['image']['tmp_name'];
- $getimage = getimagesize($gambar);
- $path = "photo/"; // Set Directory
- $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
- $type = $getimage[2];
- switch($type) {
- // --- Gambar PNG --- //
- case IMAGETYPE_PNG:
- $resource = imagecreatefrompng($gambar);
- $new_layer = resize($resource,$getimage[0],$getimage[1]);
- imagepng($new_layer,$path.acakadut(9).'.'.$ext);
- break;
- // --- Gambar GIF --- //
- case IMAGETYPE_GIF:
- $resource = imagecreatefromgif($gambar);
- $new_layer = resize($resource,$getimage[0],$getimage[1]);
- imagegif($new_layer,$path.acakadut(9).'.'.$ext);
- break;
- // --- Gambar JPEG / JPG --- //
- case IMAGETYPE_JPEG:
- $resource = imagecreatefromjpeg($gambar);
- $new_layer = resize($resource,$getimage[0],$getimage[1]);
- imagejpeg($new_layer,$path.acakadut(9).'.'.$ext);
- break;
- // --- If Invalid Type (Ekstension) --- //
- default:
- echo "Yang Lu Upload Bukan Gambar Njeng -_-";
- exit;
- break;
- }
- }
- if(@copy($path.acakadut(9).'.'.$ext)) {
- echo 'Gagal Njeng';
- } else {
- $photo = acakadut(9).'.'.$ext;
- echo('File Ter-Upload -> '.$photo);
- }
- }
- echo('<!DOCTYPE html>
- <html>
- <head>
- <title>Upload Resize</title>
- </head>
- <body>
- <div class="container">
- <form action="" method="post" enctype="multipart/form-data">
- <input type="file" name="image" />
- <input type="submit" name="upload" value="upload" />
- </form>
- </div>
- </body>
- </html>');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement