mkdir() permission denied, chmod and fopen() errors

Discussion in 'PHP' started by amitbravo, May 18, 2008.

  1. #1
    <?php
    mkdir("amit",0755) or exit("Unable to create folder");
    chmod("amit",0777) or exit("Unable to change mode");
    $file=fopen("amit/index.htm","x") or exit("Unable to create file!");
    fwrite($file,"Hello world!");
    chmod("amit",0755);
    ?>

    Probably you understand work of the piece of code.

    I would need to create a directory e.g. "amit", change mode using chmod() if required to create a file named "index.htm" inside "amit" folder and writing few content during creation of "index.htm" and then change mode again of the folder to "755" for security.


    This script works very finely on my one site but same script does not work on another site hosted on different hosting server. no help from hosting side. I would need to find any alternative of the code. please guide me how can I solve the problem.

    I've also tried to use ftp functions also. it connects to the ftp but fail to change mode "ch mode" or create files e.g. "index.htm" properly.

    Please help me. thank you very much for your valuable comments, suggestions and advices in advance.

    Kindest regards to all php gurus
    Amit
     
    amitbravo, May 18, 2008 IP
  2. allaboutgeo

    allaboutgeo Peon

    Messages:
    85
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It looks like your host does not allow these functions.
     
    allaboutgeo, May 18, 2008 IP
  3. amitbravo

    amitbravo Banned

    Messages:
    94
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    is there any alternative of this if host does not allow these functions

     
    amitbravo, May 18, 2008 IP
  4. allaboutgeo

    allaboutgeo Peon

    Messages:
    85
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I can only think of creating these directories manually using your ftp software.
     
    allaboutgeo, May 18, 2008 IP
  5. amitbravo

    amitbravo Banned

    Messages:
    94
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Remember Blogger.com ? if you run your own blog site and you need to give ftp detail when setting up your blog site and blogger does the same thing .. it creates folders, creates .html files using php.. how do they do it ?


     
    amitbravo, May 18, 2008 IP
  6. allaboutgeo

    allaboutgeo Peon

    Messages:
    85
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    They do the same thing that you are doing. But they are running dedicated servers, they are not on shared hosting. Do you have dedicated server or shared hosting?

    Ask your host if they have not disabled these functions.
     
    allaboutgeo, May 18, 2008 IP
  7. amitbravo

    amitbravo Banned

    Messages:
    94
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    whether they are running bloggers.com on dedicated server but a user that has his own site 99% times on shared server like me. they can not complain .."change the hosting and then bloggers.com will work for you". they work it through ftp function but how is the question ?


     
    amitbravo, May 18, 2008 IP
  8. amitbravo

    amitbravo Banned

    Messages:
    94
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    is there any one who could solve my problem .. I would happy to pay $ provided it works.

    directory creation , and writing files are resticted
    e.g. mkdir() , chmod() , even fopen() is not working when mode sets to "w" ( writing ).. fopen works if it sets to "r" (read only).

    Kindly advice if there is any alternative through ftp functions ..or what ?


     
    amitbravo, May 20, 2008 IP
  9. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #9
    What about :
    1. creating a directory from your cPanel or your FTP client manually (not by mkdir() PHP function),
    2. chmod the directory as writable,
    3. and creating some files there with PHP function.
     
    xrvel, May 20, 2008 IP