| Server IP : 172.67.216.113 / Your IP : 172.71.28.145 [ Web Server : Apache System : Linux cpanel01wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.59.el6.x86_64 #1 SMP Thu Dec 6 05:11:00 EST 2018 x86_64 User : cp648411 ( 1354) PHP Version : 7.2.34 Disable Function : NONE Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home2/cp648411/public_html/kainumber.com/convert/ |
Upload File : |
<?php
$folder = isset($_GET['folder']) ? rtrim($_GET['folder'], '/') . '/' : '';
$file = isset($_GET['file']) ? basename($_GET['file']) : '';
if ($folder && $file) {
$source = $folder . $file;
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (file_exists($source) && in_array($ext, ['jpg', 'jpeg', 'png'])) {
$destination = $folder . pathinfo($file, PATHINFO_FILENAME) . '.webp';
if (convertToWebp($source, $destination)) {
// ลบไฟล์ต้นฉบับ
//unlink($source);
echo "✅ แปลงและลบไฟล์ต้นฉบับเรียบร้อย → <a href='index.php?folder=" . urlencode($folder) . "'>กลับ</a>";
} else {
echo "❌ แปลงไฟล์ไม่สำเร็จ";
}
} else {
echo "❌ ไฟล์ไม่พบหรือไม่รองรับ";
}
} else {
echo "❌ ข้อมูลไม่ครบ";
}
function convertToWebp($source, $destination, $quality = 80) {
$info = getimagesize($source);
$mime = $info['mime'];
switch ($mime) {
case 'image/jpeg':
$image = imagecreatefromjpeg($source);
break;
case 'image/png':
$image = @imagecreatefrompng($source);
imagepalettetotruecolor($image);
imagealphablending($image, true);
imagesavealpha($image, true);
break;
default:
return false;
}
$result = imagewebp($image, $destination, $quality);
imagedestroy($image);
return $result;
}
?>