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

PHP: Overwriting files

Options
  • 03-10-2004 4:31pm
    #1
    Registered Users Posts: 9,190 ✭✭✭


    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 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 Posts: 9,190 ✭✭✭RobertFoster


    thank you, just what I was looking for :)


Advertisement