April 20, 2012

How to check if a folder exists using PHP

Question by edsonlp1

I have this code to check if a folder exists using PHP and it works correctly with xampp in windows, but when I try to move that page to a server, it doesn’t work.

Here is my code:

  function validate (&$valores, &$errores, $campo, $carpeta)
    {
    $valores [$campo] = $carpeta;
            if ((file_exists($carpeta) && is_dir($carpeta))==false)
            {
                    $errores[$campo] = true;                   
            }
            else
            {
                    $errores[$campo] = false;
            }
    }

There is an alternative to the code that I’m doing?

Thanks in advance

Answer by edsonlp1

Solution:
I added to PHP open_basedir folders and files I wanted to change, and then with Filezilla I’ve modified the read / write permission and fixed.

Answer by Starx

Your code should operate fine on both platforms, so its not this issue.

Usually, such problem due to the naming system. The linux based OS using strict case sensitive naming system.

So try to fix that.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!