MyBlogShare

Proses Upload Image PHP

Jul 10th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. <?php
  2.    
  3.     $image = base64_decode($_POST['foto']);
  4.     $namaimage =  rand(1, 10000);
  5.     $tanggal = date("Y-m-d");
  6.  
  7.     $nama = "image-".$tanggal.$namaimage;
  8.  
  9.     //lokasi hasil upload image
  10.     $targer_dir = "Foto/".$nama.".jpeg";
  11.  
  12.     if (file_put_contents($targer_dir, $image)) {
  13.         echo json_encode(array('response'=>'Success'));
  14.     }else{
  15.         echo json_encode(array("response" => "Image not uploaded"));
  16.     }
  17.    
  18. ?>
Add Comment
Please, Sign In to add comment