Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!