Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [mkdir] exists or not

  1. #1
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default [mkdir] exists or not

    How to check if a directory if exists or not?

    if($induk[$i] != 'root'){
    try{
    mkdir("../../stok/".$induk[$i], 777);
    mkdir("../../thumbs/".$induk[$i], 777);
    }
    catch(Exception $e){
    //nothing to do
    }
    mkdir("../../stok/".$induk[$i]."/".$kategori[$i], 777);
    mkdir("../../thumbs/".$induk[$i]."/".$kategori[$i], 777);
    }
    else{
    mkdir("../../stok/".$kategori[$i], 777);
    mkdir("../../thumbs/".$kategori[$i], 777);
    }
    I've tried to use try catch Exception, but there's no effect at all.

    Hope that somebody can help me.
    Thanks
    Last edited by sysout; 02-16-2009 at 12:57 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Code:
    <?php
    $file = "some_file.txt";
    if(file_exists($file)){
      echo "The file ".$file." exists!";
    }
    else {
      echo "Sorry, the file ".$file." doesn't exist!";
    }
    ?>
    Jeremy | jfein.net

  3. #3
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    can it effects directory?

    Thanks

  4. #4
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    What do you mean 'effect'?
    Jeremy | jfein.net

  5. #5
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    file_exists($file) -> can it be done for :

    $folder = "../../stok/Temp";

    file_exists($folder);

    is it works?

  6. #6
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    File_exists returns 1 or 0. So no... You'd have to do:
    Code:
    <?php
    // ... code here
    echo file_exists($folder);
    ?>
    Which will echo 1 if it exists, and nothing if it doesn't.
    Jeremy | jfein.net

  7. #7
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    great...it works...thanks a lot palz..

    You're really expert, excellent

  8. #8
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    I'm glad to help you sysout! Your welcome!

    It seems your topic is solved... Please set the status to resolved.. To do this:
    Go to your first post ->
    Edit your first post ->
    Click "Go Advanced" ->
    Then in the drop down next to the title, select "RESOLVED"
    Jeremy | jfein.net

  9. The Following User Says Thank You to Nile For This Useful Post:

    sysout (02-16-2009)

  10. #9
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    yeap..absolutely done..

    Thanks a lot palz, hope that I can help you too

  11. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    File_exists returns 1 or 0.
    Actually, true or false. In PHP these are hacked up with 1 and the empty string, ''. Why? Why are the two equivalents taken from different types? Why do people still use PHP? Nobody knows.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •