PHP - Scandir does not work

Asked

Viewed 262 times

2

I’m in trouble with scandir I can’t locate the directory at all, every time I get the following Warning

System cannot find specified path.

Check my code. I use Wamp X64, Windows 10 and PHP 5.6:

<?php

  $pasta = filter_input(INPUT_GET, 'pasta');          
  $tamanho = filter_input(INPUT_GET, 'tamanho');    

   /* separador */
  $separador = '/galeriaimg/';

  // aqui recebo somente o valor que preciso ou seja o nome da pasta
  $valor  = explode($separador, $pasta);

  // repassando somente o valor necessário para a variavel
  $pasta = $valor[1];

  // Formas que eu tentei obter o retorno do Scandir todas sem sucesso!
  $dir = 'http://localhost:3030/wpauditoria/images/biblioteca/$tamanho/galeriaimg/$pasta';
  $dir = $_SERVER['DOCUMENT_ROOT']."/wpauditoria/images/biblioteca/$tamanho/galeriaimg/$pasta";
  $dir = "../../../images/biblioteca/$tamanho/galeriaimg/$pasta";
  $dir = "/wpauditoria/images/biblioteca/$tamanho/galeriaimg/$pasta";

   $files = scandir($dir);

  //echo (json_encode($files));

 ?>
  • Where is located "physically" the wpauditoria folder?

  • Inside the www folder in Wamp c:/wamp64/www/wpauditoria

  • And where your PHP script is located?

  • Did you mean the code ? In that folder ! It’s the localhost ..

  • Yes the PHP code you posted in the question, in which folder is it? Inside wpauditoria?

  • Yes inside this folder ! But its subdivided is in this way wpaudit/panel-admin/include/galeriaimg/ the PHP script of the question

  • Okay, but I need to know where the php file is at least, regardless of subdivisions, unless you have multiple php files each in a folder that do the same thing.

  • You are on this path ... C:/wamp64/www/wpaudit/dashboard-admin/include/galeriaimg/gallery.php

  • Already the images that scandir should search is in this location c:/wamp64/wpaudit/images/library/medium/galeriaimg/gallery/

  • And by the browser you access php directly like this http://localhost/wpauditoria/painel-admin/include/galeriaimg/ga‌​leria.php or you make include in other . php?

  • Just one detail, the port was missing so it would look like this localhost:3030/wpaudit/dashboard-admin/galeriaimg/gallery.php

Show 6 more comments

1 answer

1


I found the problem.

I’m using the plugin responsivefilemanager to select the files and this plugin has an option to create images in preset size folders etc, these settings can be set in (config.php) of the plugin.

So, when the image is too small, it doesn’t create the folder stipulated to resize in the "medium" directory (it was inside this directory that I customized the resized images) and that caused the error because the path where he was really looking for didn’t exist, after all I uploaded a very small image that was not necessary to resize..

another important detail is the way to search with scandir. Here it only worked when called the $_SERVER['DOCUMENT_ROOT'] before the location where the script is.

Thus:

$dir = $_SERVER['DOCUMENT_ROOT']."/wpauditoria/images/biblioteca/medium/galeriaimg/galeria;

Browser other questions tagged

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