Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
Raspberry Pi Server php does not work from outside local network

I have been making a small page on my server to display some photo albums. This is on an nginx server on a raspberry pi 4. When I try to access the page from my laptop or phone when they are on wifi, everything loads correctly. However, when I use my phone with LTE, for example, the php requests do not work. I checked with my laptop using my wireless hotspot and I had the same issue. I never get the "200" code that my browser is waiting for. I do not get an error either. It is as though the http request disappears. I have other pages on this same server where the php is working correctly, one of which is almost the exact same as this code. The php I am trying to use is one which returns file and album names as a long string. Expected output would be:

Siblings|Wyoming|Utah|Skiing|

This all works when accessed from my local network. In the past I have used much more elaborate php files to access security camera footage and also send shell scripts to turn a relay on and off. These worked from anywhere in the world, not just my network. I know very little about this stuff, so I'm hoping I am just missing something obvious that an expert can recognize immediately. :) I will include my code below.

getfiles.php

<?php
    function clean_scandir($dir){
        return array_values(array_diff(scandir($dir),array('.','..')));
    }
    
    $directory = $_GET['dir'];
    $files = clean_scandir("/var/www/html/" . $directory);
    foreach($files as $file){
        $fileStr .= $file . "|";
    }
    echo $fileStr;
?>

And the javascript that is trying to use this php:

function getAlbums(){
    var xmlhttp = new XMLHttpRequest();     
    xmlhttp.onreadystatechange = function(){
        if(this.readyState == 4 && this.status == 200){
            console.log("return packet = " + this.response);
            var albumArray = this.response.split("|");
            albumArray.pop(); //remove empty last element
            for (var i = 0; i < albumArray.length; i++){
                console.log("album " + i + " = " + albumArray[i]);
            }
            getThumbnail(albumArray);
            setTimeout(() => { 
                populateAlbums(albumArray); //waits 1 sec for thumbnail requests to finish before loading thumbnails
            }, 1000);
            
        }
    }

    var urlString = "getfiles.php?dir=" + "photos/";
    xmlhttp.open("GET", urlString, true);
    xmlhttp.send();
}

The code never arrives at the console.logs that are within the big 'if' statement, I am assuming because the status never reaches 200. I do not get any other number like a 500 code. It just remains blank.

I have tried slowly modifying the php code. If the file is simply:

echo "php successful";

then it works. But for some reason the full code is causing issues. Sometimes the issues do not act the same each time either.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda