( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
header('Access-Control-Allow-Origin: *');
$dirname = "v/uploads/raw/";
$dirname2 = "v/uploads/gthumbs/";
$ran = rand(10000000000000,8888888888888);
$uploadfile = trim($dirname)."/".$ran.".jpg";
$uploadfile2 = trim($dirname2)."/".$ran.".jpg";
$source ="v/uploads/raw/$uploadfile";
$image_path="v/uploads/raw/$uploadfile";
$check ="v/uploads/raw/$uploadfile";
// If uploading file
if ($_FILES) {
/* print_r($_FILES);*/
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
list($source_width, $source_height, $source_type) = getimagesize($uploadfile);
if ($source_type === NULL) {
return false;
}
switch ($source_type) {
case IMAGETYPE_GIF:
$image = imagecreatefromgif($source);
$bg = imagecreatetruecolor(imagesx($image), imagesy($image));
imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
imagealphablending($bg, TRUE);
imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
imagedestroy($image);
$quality = 100;
$rand= rand(100000000000,9999999999);
$destination="v/uploads/raw/$rand.jpg";
$image_path="v/uploads/raw/$rand.jpg";
imagejpeg($bg, $destination, $quality);
imagedestroy($bg);
$upload="$rand.jpg";
$source =$destination;
$file = $upload;
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($source);
$bg = imagecreatetruecolor(imagesx($image), imagesy($image));
imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
imagealphablending($bg, TRUE);
imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
imagedestroy($image);
$quality = 100;
$rand= rand(100000000000,9999999999);
$destination="v/uploads/raw/$rand.jpg";
$image_path="v/uploads/raw/$rand.jpg";
imagejpeg($bg, $destination, $quality);
imagedestroy($bg);
$upload="$rand.jpg";
$source =$destination;
$file = $upload;
break;
default:
$file = $ran.".jpg";
return false;
}
echo $file;
}
}