* @Date Created: 2020/11/15 19:31:15
* @Last modified by: amirhp-com
BlackSwan Upload File from URL to Web Server v.14
SELF-DESTRUCTION WAS SUCCESSFUL, BYE 👋!');
}
?>
Developed by amirhp-com | Give star on Github | your_ip: = get_real_IP_address(); ?> [ root / new? ]
URL-Address to WebServer
document.title = 'Uploading ...';
document.querySelector('h1').innerHTML += `
Please wait until process complete or Press ESC key to cancel" . print_r($fp, 1) . "
";
die("
Upload complete!");
}
$headers = array_change_key_case(get_headers($url, 1));
$filesize = $headers['content-length'];
ob_end_flush(); ob_flush(); flush(); ob_start();
if ($filesize < 1) {
echo "" . print_r($headers, 1) . "
";
echo "" . print_r($_SERVER, 1) . "
";
exit;
}
$read_bytes = 0; $num = 0; $progress = 1;
$steps = floor($filesize / 2048) / 300 < 0 ? 3 : floor($filesize / 2048) / 300;
echo "";
while (!feof($remote)) {
$buffer = fread($remote, 2048);
fwrite($local, $buffer);
$read_bytes += 2048;
$num++;
if ($num > 4 && $steps > 1) {
if ($num % $steps == 0) {
$progress = min(100, 100 * $read_bytes / $filesize);
echo "";
}
}
ob_end_flush(); ob_flush(); flush(); ob_start();
}
fclose($remote);
fclose($local);
$should_extract = "https://wordpress.org/latest.zip" == $url;
echo "";
ob_end_flush(); ob_flush(); flush();
if ($should_extract) {
echo "";
ob_end_flush(); ob_flush(); flush(); ob_start();
$rootDir = __DIR__;
$zipFile = $path_full;
$tempDir = $rootDir . '/temp/wordpress';
$continue = false;
$zip = new ZipArchive;
if ($zip->open($zipFile) === TRUE) {
$zip->extractTo($rootDir . '/temp');
$zip->close();
$continue = true;
echo "";
echo "";
ob_end_flush(); ob_flush(); flush(); ob_start();
} else {
echo "";
ob_end_flush(); ob_flush(); flush(); ob_start();
}
if ($continue) {
if (!is_dir($tempDir)) {
echo "";
ob_end_flush(); ob_flush(); flush(); ob_start();
}
// Step 3: Move files from the 'wordpress' folder to the root directory
$files = scandir($tempDir); $jf = 0; $jfl = 0;
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$source = $tempDir . '/' . $file;
$destination = $rootDir . '/' . $file;
// Move the file or directory
if (is_dir($source)) {
$jfl++; rename($source, $destination);
} else {
$jf++; rename($source, $destination);
}
}
}
echo "";
ob_end_flush(); ob_flush(); flush(); ob_start();
// Step 4: Remove the temporary folder
$tempPath = $rootDir . '/temp';
if (is_dir($tempPath)) {
if (rmdir($tempPath)) {
echo "";
ob_end_flush(); ob_flush(); flush(); ob_start();
} else {
// Fallback to recursive deletion if the folder isn't empty
rmdir_recursive($tempPath);
echo "";
ob_end_flush(); ob_flush(); flush(); ob_start();
}
}else{
echo "";
ob_end_flush(); ob_flush(); flush(); ob_start();
}
// Step 5: Optionally, delete the ZIP file
if (file_exists($zipFile)) {
@unlink($zipFile);
@unlink($folder . "/license.txt");
@unlink($folder . "/readme.html");
@unlink($folder . "/xmlrpc.php");
echo "";
ob_end_flush(); ob_flush(); flush(); ob_start();
}
}
}
ob_end_flush();ob_flush(); flush();
echo "";
echo "all done ./";
exit;
}
?>
DO NOT KEEP THIS FILE ON YOUR SERVER, DELETE IT AS SOON AS YOU'RE DONE. [🗑️]
0 ? "$h:" : "") . sprintf('%02d', $m) . ':' . sprintf('%02d', $s);
}
function rmdir_recursive($dir) {
$files = array_diff(scandir($dir), ['.', '..']);
foreach ($files as $file) {
$path = $dir . '/' . $file;
is_dir($path) ? rmdir_recursive($path) : unlink($path);
}
return rmdir($dir);
}
/*##################################################
Lead Developer: [amirhp-com](https://amirhp.com/)
##################################################*/