Frage

Hey i'm trying to make my website delete a file using the unlink(); function. but when i try it comes up with this:

Warning: unlink() [function.unlink]: cURL does not allow unlinking in /home/nzcraftn/public_html/filenz/user/delete.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at /home/nzcraftn/public_html/filenz/user/delete.php:18) in /home/nzcraftn/public_html/filenz/user/delete.php on line 27

I am using this code:

if($_SESSION['user'] == $who) {
    $delete = unlink("http://www.filenz.nzcraft.net/$dl");

    if($delete) {
    $_SESSION['message'] = "<div style='color: #00FF00'>File deleted!</div>";
    header("Location: index.php");
    mysql_query("DELETE FROM fileinfos WHERE(`id`='$id')") or die(mysql_error());

} else {
    $_SESSION['message'] = "<div style='color: #FF0000'>Error while deleting!</div>";
    header("Location: index.php");
    }
}

IF you could tell me if different way to delete files or help me fix my current problem i would appreicate it very much.

Thanks.

War es hilfreich?

Lösung

The protocol you are trying to use does not support unlinking a file. See the documentation here for more information.

Fixing this depends on your situation, you can try using a different protocol like FTP that supports file operations or use the local path to the file. It is also important to note that you need proper permissions to perform these operations and in the case of FTP a username and password.

Andere Tipps

Although you can delete files via HTTP, php's HTTP protocol wrapper does not support it. Without authentication, it would be a security hole anyway, and therefore most HTTP server don't support DELETE (apart from WebDAV). You should do one of the following:

  • Delete the file via FTP or SFTP. You'll have to configure the server, but chances are there is already an FTP or SFTP account in place. php 5's FTP and SFTP protocol wrappers support unlink, so you can use that instead of the respective deletion functions if you prefer.
  • If your server really supports WebDAV, you'll have to use the CURL extension and curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); to delete files via HTTP. Don't forget to authenticate!
  • Add a server-side script that allows file deletion. Make sure to authenticate (check user+password) and not allow CSRF attacks if you choose cookie-based authentication.

PHP documentation about wrappers says that unlink is not supported by the HTTP wrapper.

You could pass a path within the filesystem to unlink, for example:

unlink("/path_to_directory/$dl");
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top