Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts

    mkdir() not working

    Hey all,

    I'm currently building a website where users can create pages which pictures can eventually be uploaded to. I want it so when a new page is created a folder is made on the server specific to that event which will then contain all photo's for that event.

    This is what I'm currently working with but for some reason just isn't working:

    Attempt style 1:
    PHP Code:
    $newfolder mkdir("../imagehub/events/".$evt.$name0777); 
    Attempt style 2:
    PHP Code:
    $newfolder mkdir("../imagehub/events/$evt$name"0777); 
    Attempt style 3:
    PHP Code:
    if(!mkdir("../imagehub/events/$evt$name"){
        echo 
    "File not created";
    }else{ 
      echo 
    "File Created";
    }; 
    Attempt style 4:
    PHP Code:
    $newfolder "../imagehub/events/".$evt.$name;
    mkdir($newfolder0777); 

    I presume I'm going wrong somewhere but a little nudge in the right direction would be much appreciated!

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    It may be a server permissions problem - quite common these days.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Make sure to check your error logs as well. I can see at least two common ones; the first as mentioned is a simple permission issue, which may be resolvable via a chmod or umask. Typically you'll need to set the ownership of the ../imagehub/events directory to that of your apache user (nobody, www-user, apache, different names I'm afraid), group it to apache, or allow write access to everyone. I'd go for either own or group with read, write, execute. The easiest fix is to let PHP make the directories for you, they should automatically take the ownership to the apache user.

    The other issue that could be common is a simple incorrect filepath. This is relative, it assumes that you will find this path a directory above the executing script. If it can't find the ../imagehub/events path, it will fail. The default handing of mkdir is to not recursively create the directory structure for you (can be forced with the third parameter, but I won't recommend doing so until you at least determine what the issue is).

  • #4
    Regular Coder
    Join Date
    Jul 2011
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks both of you. I managed to get it to work by changing the path name to another area. Not sure what was the issue with the original one but it seems to be fine now. Thanks again.


  •  

    Posting Permissions

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