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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts

    Creating a directory...

    Can someone please point me in the right direction of where I can read up on how to create a directory on my website using PHP!

    Thanks in advance

    Taylor.

  • #2
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Okay - change that - I know how to create a directory now.. However I wanted to create a index.php file in the directory - but it wont do it - it just creates the directory - all I see in examples that I have read is how to create a .txt file - but I want a .php file WAAAA! lol

    Any help would be greatly appreciated!

    Thanks in advance!

    Taylor.

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Just change the extension in the txt file script to file.php instead of file.txt

  • #4
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    It wont work - it only creates a .txt not .php - let me show ya:

    <? $res_dir = "../$url";
    $res_file = $res_dir."/index.php";

    if (!file_exists ($res_file))
    {
    if (!mkdir ($res_dir, 0700)) die ("Server Error: Can't create directory");

    $content = "\<\? include (\"http://ysuperleague.com/system?url=$url\"); \?\>";
    $handler = fopen ($res_file, "w");
    fwrite ($handler, $content);
    fclose ($handler);
    print " CREATED !!!!!!!!";
    }

    ?>

    It creates the directory but does not create the index.php file.
    Last edited by Taylor_1978; 01-16-2004 at 01:36 AM.

  • #5
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <?php
    $makefile = fopen("index.php", "a+");
    fclose($makefile);
    ?>




    what this does is try to open a file named "index.php". it uses the access mode a+ which creates the file if it doesnt exist which is doesnt so it makes a file called "index.php".
    ~Designer's Toolz~

  • #6
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Okay _ tried this but still not making file - Can you possibly add what you are suggesting into my own code as I am obviously writing it wrong!

    <? $res_dir = "../$url";
    $res_file = $res_dir."/index.php";

    if (!file_exists ($res_file))
    {
    if (!mkdir ($res_dir, 0700)) die ("Server Error: Can't create directory");

    $content = "\<\? include (\"http://ysuperleague.com/system?url=$url\"); \?\>";
    fopen ($res_file, "a+");
    $handler = fwrite ($res_file, $content);
    fclose ($handler);
    print " CREATED !!!!!!!!";
    }


    ?>
    Thanks in advance

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    <?php

    $res_dir = "../$url";

    $res_file = $res_dir."/index.php";

    if (!file_exists ($res_file))
    {
    if (!mkdir ($res_dir, 0700)) die ("Server Error: Can't create directory");

    $content = "\<\? include (\"http://ysuperleague.com/system?url=$url\"); \?\>";
    $openfile = fopen ($res_file, "a+");
    fwrite ($openfile, $content);
    fclose ($openfile);
    print " CREATED !!!!!!!!";
    }

  • #8
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Okay - I found the problem and it turns out it is not a script error!

    The script was creating the directory but would not create the file... I tried over and over. Then, I tried to manually save a file in that directory and it stated that there was a system error... So basically - any directory made via the !mkdir would not allow any files to be stored in it... via fopen or manually... Any ideas as to why?

    Thanks in advance
    Taylor.

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    try ...
    PHP Code:
    <?
    mkdir 
    ($res_dir0777);
    fputs(fopen($res_dir.'/test.txt','w'),'test');
    chmod($res_dir ,0755);
    ?>
    Last edited by firepages; 01-18-2004 at 04:03 PM.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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