Jump to content

[SOLVED] if folder already exists then display error message?


A2xA

Recommended Posts

I have a script that makes a game hub for a member.  It is using mkdir and then chmodding it.  If the folder already exists then it gives me this error:

 

Warning: mkdir() [function.mkdir]: File exists in "SHOWS MY DIRECTORY" on line 6

 

This is an ugly/bad error message + it isn't good for security because it shows my file directorys.  If someone could tell me how to fix this I would be grateful.

 

Thanks!  ;)

wait, this only tells them that it already exists and dosen't prevent them from overwriting it.  Is there any way to do both?

 

if (file_exists($dir)) {
    echo "The hub $dir exists already";
} else {
echo "Hubs Sucessfully Added, Your Hub ID is "; echo "$dir"; 
}

Only put the code to create the file between the else statement brackets.

 

<?php

if (file_exists($dir)) {
    echo "The hub $dir exists already";
} else {
   //Put code to create file here
   echo "Hubs Sucessfully Added, Your Hub ID is "; echo "$dir"; 
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.