X7ROOT File Manager
PHP:
7.2.34
OS:
Linux
User:
cp648411
Root
/
home2
/
cp648411
/
public_html
/
kainumber.com
/
convert
📤 Upload
📝 New File
📁 New Folder
Close
Editing: convert.php
<?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; } ?>
Save
Cancel