tags:

views:

28

answers:

2

Hi, how to test if a file exist on the current computer using the application ?

I try to put the full url at my file like this, but it doesn't work :

if(file_exists("C:/wamp/www/project/photo/".$nom_photo))
        {
            echo "file exist";
            $extension=pathinfo("C:/wamp/www/project/photo/".$nom_photo,PATHINFO_EXTENSION);
            echo "<br>";
            $nom=md5($nom_photo.time().rand(0, 99999)).".".$extension;
            echo $nom;
            rename("C:/wamp/www/project/photo/".$nom_photo,"C:/wamp/www/project/photo/".$nom);
            echo "<br>";


        }

How to fix it ?

+3  A: 

PHP operates server side and has NO ACCESS to the files on the machine running the web browser, unless they are indeed the same machine.

If you are meaning to find a way to test if a file exists on the web server, the file_exists() function you mentioned should find it. There are many reasons this might fail, including safe_mode, file permissions, and using the wrong path.

gnarf
+1  A: 

The server doesn't have any access to the clients filesystem, this would be a major security flaw.

Also javascript is sandboxed so you couldn't do it on the client side either.

The only way I can think of doing this is to get the user to download a separate application that looks for the file and reports back to the server.

Neil Aitken