Skip to content

add the content of the file in a variable #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yoyes86 opened this issue May 30, 2024 · 4 comments
Open

add the content of the file in a variable #116

yoyes86 opened this issue May 30, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@yoyes86
Copy link

yoyes86 commented May 30, 2024

$query = (new Query('/file/print'))
                ->where('.id', $file['.id']);
$fileContent = $client->query($query)->read();
$content = $fileContent[0]['contents'];

but only the first line of the file is on the variable
How can I have the entire content on the variable?
It s for create the config client ovpn with certificate.

@yoyes86 yoyes86 added the question Further information is requested label May 30, 2024
@EvilFreelancer
Copy link
Owner

Hi! Can you provide more details?

@yoyes86
Copy link
Author

yoyes86 commented May 31, 2024

Hi, I have a file une Files of Mikrotik and i wanted to copy the content in a variable with this code:

$query = (new Query('/file/print'))
->where('.id', $file['.id']);
$fileContent = $client->query($query)->read();
$content = $fileContent[0]['contents'];

But only the first line of the file is on the variable;

When I debugging, I see the only first line is show on the content:

$filesQuery = (new Query('/file/print'));
files = $client->query($filesQuery)->read();
echo "<pre>Files List: "; print_r($files); echo "</pre>";
Files List: Array
(
    [0] => Array
        (
            [.id] => *D0D23
            [name] => RB2011-3011-BASE.startup-script3 - silent.rsc
            [type] => script
            [size] => 6124
            [creation-time] => may/28/2024 09:30:12
        )

    [1] => Array
        (
            [.id] => *D1AE6
            [name] => cert_export__most_ca_ovpn.crt
            [type] => .crt file
            [size] => 1229
            [creation-time] => may/30/2024 11:31:59
            [contents] => -----BEGIN CERTIFICATE-----
        )

    [2] => Array
        (
            [.id] => *D1AE7
            [name] => cert_export__most_client_ovpn.crt
            [type] => .crt file
            [size] => 1196
            [creation-time] => may/30/2024 11:31:59
            [contents] => -----BEGIN CERTIFICATE-----
        )

    [3] => Array
        (
            [.id] => *D1AE8
            [name] => cert_export__most_client_ovpn.key
            [type] => .key file
            [size] => 1858
            [creation-time] => may/30/2024 11:31:59
            [contents] => -----BEGIN ENCRYPTED PRIVATE KEY-----
        )

)

@anasamu
Copy link

anasamu commented Jul 26, 2024

fix this
$fileContent = $client->query($query)->read(false);

@fenads
Copy link

fenads commented Apr 2, 2025

Forma 1 - If you want to concatenate everything into a string:

$filesQuery = (new Query('/file/print'));
files = $client->query($filesQuery)->read();

$content =' ';

foreach ($fileContent as $file) {
$content .= $file['contents'];
}

Forma 2 - If you want to put everything together in an array:

$filesQuery = (new Query('/file/print'));
files = $client->query($filesQuery)->read();

$content = [];

foreach ($fileContent as $file) {
$content[] = $file['contents'];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants