PHP accessing files from another micro on the network

Asked

Viewed 955 times

0

I know this question can be marked as duplicate, but I haven’t found any definitive answer.

After all, it is possible to access files from a computer on the same network, using PHP, without changing Apache settings?

I did several tests listed below, I did not succeed in any of them.

<?php
    function getRealIpAddr() {

        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip=$_SERVER['HTTP_CLIENT_IP'];
        } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip=$_SERVER['REMOTE_ADDR'];
        }
        return $ip;

    } 

    echo getRealIpAddr();

    $teste = file_get_contents("file://".getRealIpAddr()."/dados_merilin/Pesquisa.pdf");

    var_dump($teste);

    $teste = file_get_contents("file:\\\\".getRealIpAddr()."\\dados_merilin\\Pesquisa.pdf");

    var_dump($teste);

    $url = file_exists("//".getRealIpAddr()."/dados_merilin/Pesquisa.pdf");
    var_dump($url);

    $url = file_exists("\\\\".getRealIpAddr()."\\dados_merilin\\Pesquisa.pdf");
    var_dump($url);

    $isFolder = is_dir("\\\\".getRealIpAddr()."\\dados_merilin");
    var_dump($isFolder);

    $isFolder = is_dir("//".getRealIpAddr()."/dados_merilin");
    var_dump($isFolder);

    $arquivo = fopen("\\\\".getRealIpAddr()."\\dados_merilin\\Pesquisa.txt", 'r');

    var_dump($arquivo);

    $arquivo = fopen("//".getRealIpAddr()."/dados_merilin/Pesquisa.txt", 'r');

    var_dump($arquivo);

?>

Since the folder dados_merilin is shared, with full access and there is the file in this folder.

The return is...

inserir a descrição da imagem aqui

So it’s possible?

  • Rafa, acess https://stackoverflow.com/questions/1153824/php-access-network-path-under-windows this will help you.

  • Changing server records would also not be an alternative for me, besides being Linux

No answers

Browser other questions tagged

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