Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP: Overwriting files

  • 03-10-2004 04:31PM
    #1
    Registered Users, Registered Users 2 Posts: 9,451 ✭✭✭


    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,451 ✭✭✭RobertFoster


    thank you, just what I was looking for :)


Advertisement