Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP: Overwriting files

  • 03-10-2004 3:31pm
    #1
    Registered Users, Registered Users 2 Posts: 9,281 ✭✭✭


    Hello,

    I set up a fairly basic PHP script which allows me to upload and download college work from whereever I am (home or college)

    I have a bit of a problem when trying to overwrite a file already in existance. I get the following error message:
    [PHP]Warning: copy(<directory>/<filename>): failed to open stream: Permission denied in /****/*******/public_html/college/upload.php on line 14[/PHP]
    Said line 14 is:
    [PHP]if (copy ($file, "$dir/$file_name")) {[/PHP]
    If you want me to put up the full scripts I will.

    I googled for a bit, but it was fruitless - results returned were about some premade script.

    Anyone got any ideas?


Comments

  • Registered Users, Registered Users 2 Posts: 885 ✭✭✭clearz


    Have a look at

    chmod($filename, $permissions);
    [PHP]
    <?php
    function file_write($filename, &$content) {
    if (!is_writable($filename)) {
    if (!chmod($filename, 0666)) {
    echo "Cannot change the mode of file ($filename)";
    exit;
    };
    }
    if (!$fp = @fopen($filename, "w")) {
    echo "Cannot open file ($filename)";
    exit;
    }
    if (fwrite($fp, $content) === FALSE) {
    echo "Cannot write to file ($filename)";
    exit;
    }
    if (!fclose($fp)) {
    echo "Cannot close file ($filename)";
    exit;
    }
    }
    ?>
    [/PHP]


  • Registered Users, Registered Users 2 Posts: 9,281 ✭✭✭RobertFoster


    thank you, just what I was looking for :)


Advertisement