how to create and write txt file with fopen in a network folder

Asked

Viewed 230 times

0

I wonder if there is a way to create , write a file txt with in a folder located outside the PHP application, in another machine on the same network . The PHP server is under Ubuntu Linux and I have to save to another Windows server. Since PHP does not support SMB how can I do this?

fopen("C:\\xampp\\htdocs\\Enviamos\\file00001.txt",'w+'); local esta ok e em outro diretório em rede 
fopen("\\192.168.10.4\\Enviamos\\file00001.txt",'w+')

1 answer

0

Simple example of an execution of this task.

<?php
// Caminho do arquivo na rede
$filename = "//10.96.1.100/Pasta/Na/Rede/Arquivo.txt";
// Modo de leitura e escrita
$mode = "w+";
// Inicializar o recurso de leitura e escrita do arquivo
$handle = fopen($filename, $mode);
// escreva no arquivo - forma 1
$arrayStr = join("", [
    "Data;Valor" . PHP_EOL, // Coloca os dados e uma quebra de linha
    "23/10/2020;1.500,55" . PHP_EOL // Coloca os dados e uma quebra de linha
]);

printf("Escrevi %s bytes no arquivo %s <br>", fwrite($handle, $arrayStr), $filename);
// Fechar arquivo
fclose($handle);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.