• XSS.stack #1 – первый литературный журнал от юзеров форума

Help generate apk filenames with numbers, PHP

kriz84

(L3) cache
Забанен
Регистрация
18.05.2023
Сообщения
180
Реакции
39
Пожалуйста, обратите внимание, что пользователь заблокирован
Hello,
I need help on my php file, I hope someone can help me
Currently my php generate APK files with random filenames, this i want to change

This code needs to be changed:
$packagebotone = generateRandomString();
$packagebottwo = generateRandomString();

$apk = generateRandomString() . "_release" . "apk;

$packagebotone = generateRandomString();
$packagebottwo = generateRandomString();
So that means the output of the APK filenames is for example zGhjJg_release.apk

But I want that the output would be app-release.apk, app-release-1.apk, app-release-2.apk and so on.

I searched myself everywhere but couldn't find information.
Can anybody help me here please?

Thanks
 
PHP:
<?php
CONST FILE_NAME = 'app-release';
CONST EXTENSION = 'apk';
CONST ROOT_DIRECTORY = '/home/www/domain'; // change your directory

// Check Root Directory
if (!is_readable(ROOT_DIRECTORY)) {
    throw new Exception("Error: The directory is not readable.");
}

// Function to get information about files
function processDirectory($dir): array
{
    $file_info = array();
    if ($handle = opendir($dir)) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != ".." && str_contains($entry, FILE_NAME)) {
                $full_path = $dir . '/' . $entry;
                if (is_dir($full_path)) {
                    $file_info = array_merge($file_info, processDirectory($full_path));
                } elseif (is_file($full_path) && pathinfo($entry, PATHINFO_EXTENSION) == EXTENSION) {
                    $file_info[] = array(
                        'name' => $entry,
                        'path' => $full_path
                    );
                }
            }
        }
        closedir($handle);
    }

    return $file_info;
}

$files = processDirectory(ROOT_DIRECTORY);

$file_name_apk = '';
$max = 0;

if(count($files) > 0){
    $regex = '/\d/';

    foreach ($files as $file){
        preg_match($regex, $file['name'], $match);
        if($match[0] > $max){
            $max = $match[0];
        }
    }

    $version = '-' . $max + 1 ?? '';
    $file_name_apk = FILE_NAME . $version . '.' . EXTENSION;
}else{
    $file_name_apk = FILE_NAME . '.' . EXTENSION;
}

echo '<pre>';
var_dump($file_name_apk);
echo '</pre>';

This code recursively goes through all the folders in the directory and gets all the files with the name app-release, later it finds the largest number in the file name, and returns the new file name in the $file_name_apk variable.
 
Пожалуйста, обратите внимание, что пользователь заблокирован
PHP:
<?php
CONST FILE_NAME = 'app-release';
CONST EXTENSION = 'apk';
CONST ROOT_DIRECTORY = '/home/www/domain'; // change your directory

// Check Root Directory
if (!is_readable(ROOT_DIRECTORY)) {
    throw new Exception("Error: The directory is not readable.");
}

// Function to get information about files
function processDirectory($dir): array
{
    $file_info = array();
    if ($handle = opendir($dir)) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != ".." && str_contains($entry, FILE_NAME)) {
                $full_path = $dir . '/' . $entry;
                if (is_dir($full_path)) {
                    $file_info = array_merge($file_info, processDirectory($full_path));
                } elseif (is_file($full_path) && pathinfo($entry, PATHINFO_EXTENSION) == EXTENSION) {
                    $file_info[] = array(
                        'name' => $entry,
                        'path' => $full_path
                    );
                }
            }
        }
        closedir($handle);
    }

    return $file_info;
}

$files = processDirectory(ROOT_DIRECTORY);

$file_name_apk = '';
$max = 0;

if(count($files) > 0){
    $regex = '/\d/';

    foreach ($files as $file){
        preg_match($regex, $file['name'], $match);
        if($match[0] > $max){
            $max = $match[0];
        }
    }

    $version = '-' . $max + 1 ?? '';
    $file_name_apk = FILE_NAME . $version . '.' . EXTENSION;
}else{
    $file_name_apk = FILE_NAME . '.' . EXTENSION;
}

echo '<pre>';
var_dump($file_name_apk);
echo '</pre>';

This code recursively goes through all the folders in the directory and gets all the files with the name app-release, later it finds the largest number in the file name, and returns the new file name in the $file_name_apk variable.
Did you wrote this all for me? Thank you very much!!
I will try it tomorrow, so I just need to change the root dir.
Much Thanks, this is exactly what I wanted!
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх