/
home
/
u764571690
/
domains
/
savitrfoundation.com
/
public_html
/
/home/u764571690/domains/savitrfoundation.com/public_html
mkdir
upload
Name
Size
Mode
Actions
admin/
-
0755
rm
ajax/
-
0755
rm
api/
-
0755
rm
assets/
-
0755
rm
cache/
-
0755
rm
certificate_view/
-
0755
rm
css/
-
0755
rm
documents_upload/
-
0755
rm
F2/
-
0755
rm
finger data/
-
0755
rm
functions/
-
0755
rm
hts-cache/
-
0755
rm
js/
-
0755
rm
logs/
-
0755
rm
pages/
-
0755
rm
privacy policy/
-
0755
rm
savitrfoundation/
-
0755
rm
scholar/
-
0755
rm
terms and conditions/
-
0755
rm
tmp/
-
0755
rm
uploads/
-
0755
rm
.htaccess
3583
0644
edit
dl
rm
.htaccess.htaccess
9223
0644
edit
dl
rm
.user.ini
623
0644
edit
dl
rm
ads.txt
58
0644
edit
dl
rm
application.php
41647
0644
edit
dl
rm
backblue.gif
4243
0644
edit
dl
rm
careers.php
18402
0644
edit
dl
rm
fade.gif
828
0644
edit
dl
rm
how to apply.php
44852
0644
edit
dl
rm
hts-log.txt
2738
0644
edit
dl
rm
index.php
50
0644
edit
dl
rm
ngo_account_open.php
27984
0644
edit
dl
rm
our_scholars.php
11882
0644
edit
dl
rm
php.ini
617
0644
edit
dl
rm
reupload_document.php
6038
0644
edit
dl
rm
robots.txt
291
0644
edit
dl
rm
scholarshipapply.php
219769
0644
edit
dl
rm
scholarshipportal.php
89993
0644
edit
dl
rm
sendmail.php
2720
0644
edit
dl
rm
sitemap.xml
3743
0644
edit
dl
rm
submit-internship-application.php
8856
0644
edit
dl
rm
sw.js
156
0644
edit
dl
rm
upload_document_main.php
6121
0644
edit
dl
rm
Edit:
/home/u764571690/domains/savitrfoundation.com/public_html/reupload_document.php
(6038B)
<?php error_reporting(E_ALL); ini_set('display_errors', 1); date_default_timezone_set('Asia/Kolkata'); require_once 'scholar/db.php'; // Return JSON responses header('Content-Type: application/json'); /** * Convert image to WebP format with quality setting */ function convertToWebP($source, $destination, $quality = 80) { $imageInfo = @getimagesize($source); if (!$imageInfo) { return false; } $mime = $imageInfo['mime']; $width = $imageInfo[0]; $height = $imageInfo[1]; // Create image resource based on mime type switch ($mime) { case 'image/jpeg': case 'image/jpg': $image = @imagecreatefromjpeg($source); break; case 'image/png': $image = @imagecreatefrompng($source); break; case 'image/gif': $image = @imagecreatefromgif($source); break; default: return false; } if (!$image) { return false; } // Ensure destination has .webp extension $pathInfo = pathinfo($destination); $webpDestination = $pathInfo['dirname'] . '/' . $pathInfo['filename'] . '.webp'; // Convert to WebP $success = imagewebp($image, $webpDestination, $quality); imagedestroy($image); return $success ? $webpDestination : false; } try { // Check if form was submitted if ($_SERVER['REQUEST_METHOD'] !== 'POST') { throw new Exception('Invalid request method'); } // Get form data $documentId = isset($_POST['document_id']) ? (int)$_POST['document_id'] : 0; $applicantId = isset($_POST['applicant_id']) ? (int)$_POST['applicant_id'] : 0; $documentType = isset($_POST['document_type']) ? trim($_POST['document_type']) : ''; // Validate required fields if (!$documentId || !$applicantId || !$documentType) { throw new Exception('Missing required fields'); } // Check if file was uploaded if (!isset($_FILES['document_file']) || $_FILES['document_file']['error'] !== UPLOAD_ERR_OK) { throw new Exception('File upload error'); } $file = $_FILES['document_file']; // Validate file type $fileExtension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif']; if (!in_array($fileExtension, $allowedExtensions)) { throw new Exception('Only images (JPG, PNG, GIF) allowed'); } // Validate file mime type $finfo = finfo_open(FILEINFO_MIME_TYPE); $mimeType = finfo_file($finfo, $file['tmp_name']); finfo_close($finfo); $allowedMimes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif']; if (!in_array($mimeType, $allowedMimes)) { throw new Exception('Invalid file format'); } // Get the old document details $stmt = $pdo->prepare("SELECT * FROM documents WHERE id = ? AND applicant_id = ?"); $stmt->execute([$documentId, $applicantId]); $oldDocument = $stmt->fetch(PDO::FETCH_ASSOC); if (!$oldDocument) { throw new Exception('Document not found'); } // Verify the document type matches if ($oldDocument['document_type'] !== $documentType) { throw new Exception('Document type mismatch'); } // Get applicant details to get the folder path $stmt = $pdo->prepare("SELECT application_id FROM applicants WHERE applicant_id = ?"); $stmt->execute([$applicantId]); $applicant = $stmt->fetch(PDO::FETCH_ASSOC); if (!$applicant) { throw new Exception('Applicant not found'); } // Use the same directory as the old document $oldPath = $oldDocument['document_path']; $directory = dirname($oldPath); // Ensure directory exists if (!file_exists($directory)) { mkdir($directory, 0777, true); } // Generate new filename with WebP extension $fileName = $documentType . '_' . time() . '.webp'; $filePath = $directory . DIRECTORY_SEPARATOR . $fileName; // Convert to WebP format $webpPath = convertToWebP($file['tmp_name'], $filePath, 80); if (!$webpPath) { throw new Exception('Failed to convert image to WebP format'); } // Get WebP file size for response $webpSize = filesize($webpPath); $originalSize = $file['size']; // Begin transaction $pdo->beginTransaction(); try { // Delete old document file if it exists if (file_exists($oldPath)) { unlink($oldPath); } // Update document record in database $stmt = $pdo->prepare(" UPDATE documents SET document_name = ?, document_path = ?, status = 'pending', uploaded_at = NOW() WHERE id = ? AND applicant_id = ? "); $stmt->execute([ $file['name'], $webpPath, $documentId, $applicantId ]); // Commit transaction $pdo->commit(); // Return success response with compression details echo json_encode([ 'success' => true, 'message' => 'Document re-uploaded and converted to WebP successfully. It will be reviewed shortly.', 'document_id' => $documentId, 'file_name' => $file['name'], 'original_size' => round($originalSize / 1024, 2), 'webp_size' => round($webpSize / 1024, 2), 'saved_percentage' => round((($originalSize - $webpSize) / $originalSize) * 100, 2) ]); } catch (Exception $e) { // Rollback transaction $pdo->rollBack(); throw $e; } } catch (Exception $e) { // Return error response echo json_encode([ 'success' => false, 'message' => $e->getMessage() ]); } ?>
Save
cmd:
run