Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

[Bug] SOCORRO !! Meu Apache2 não quer ler meu index.php

Já estou a dias neste problema :( Estou rodando um servidor linux com ubuntu, o apache2 está instalado e consegue ler perfeitamente outras páginas .php mas esta em específico ele detecta somente o código fonte como na imagem abaixo:

Insira aqui a descrição dessa imagem para ajudar na acessibilidadeSegue o código do arquivo index.php:

<?php
function dirToArray($dir) {
   $res = array();
   $cdir = scandir($dir);
   foreach ($cdir as $key => $value){
      if (!in_array($value,array(".",".."))){
         if (is_dir(str_replace("\\", "/", $dir . DIRECTORY_SEPARATOR . $value))) {
            dirToArray(str_replace("\\", "/", $dir . DIRECTORY_SEPARATOR . $value));
         } else {
            $hash = hash_file('sha1', $dir . "/" . $value);
            $size = filesize($dir . "/" . $value);
            $path = str_replace("files/", "", $dir . "/" . $value);
            $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . $dir . "/" . $value;
            if (strpos($path, "libraries") !== false) {
               $type = "LIBRARY";
            } else if (strpos($path, "mods") !== false) {
               $type = "MOD";
            } else if (strpos($path, "versions") !== false) {
               if (substr($path, -5) == ".json") {
                  $type = "VERIONSCUSTOM";
               } else if(substr($path, -4) == ".jar"){
                  $type = "VERIONS";
               } else {
                  $type = "FILE";
               }
            } else {
               $type = "FILE";
            }
            echo "{\"path\":\"$path\",\"size\":$size,\"sha1\":\"$hash\",\"url\":\"$url\",\"type\":\"$type\"},";
         }
      }
   }
}

header("Content-Type: application/json; charset=UTF-8");
echo "[", dirToArray("files"), "\"\"]";
?>
1 resposta
solução!

Oi, Nicolas.

Está retornando exatamente o que você pediu

Um JSON. Array de objetos, com os campos: hash, size, path e url

Instale uma extensão no chrome para visualizar melhor o formato JSON

JSON Formatter

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software