The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP unlink() issue

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #33540

    I cannot seem to get this to work. I have tried multiple things, and all of them give me the same PHP error, that there is no such file or directory in the site. This isn’t true, because if I FTP to the site, I can SEE that these files are there… Anyway, here is what I’m doing:


    I understand that unlink does NOT take a URL, and I store some url info in the DB, so I strip that out. So I am basically just using a straight path to the file, since I’m in the root directory of the site when doing this. So that line above would actually run as something like this:


    Any ideas on this? I’ve also tried doing it this way:

    unlink($_SERVER . str_replace(“”,””,$films));

    Again, same result – nothing I’ve done will work, and it can never ‘find’ the file, even though it’s there. Please, please help if you can. Thanks.


    @TT_Mark, it doesn’t make a difference – I get the same error again :( Any other ideas?


    Make sure you get the right path to the file.
    It’s a better practice to always use ABSOLUTE path.

    Try to print the path and check if it does exist:

    $file_path=$_SERVER . str_replace("","",$films);

    echo $file_path;
    echo '

    BTW, it’ll be helpful if you can show your PHP error.


    @ddliu – I don’t think you read my original post – I DID try using the $_SERVER, but with no success. I have tried multiple things – the file DOES exist (it’s being used in multiple places on the site), but I want the user to have the option to delete it. The error I get says:

    Warning: unlink(/home/syxbit/public_html/ Flops.png
    ) [function.unlink]: No such file or directory in /home/syxbit/public_html/ on line 27

    The output of:

    echo $_SERVER . str_replace("","",$films);

    is exactly the path in the unlink.

    Any other ideas?


    The only thing I can guess is the file path issue.

    I see there is a new line at the end of the path:

    Warning: unlink(/home/syxbit/public_html/ Flops.png

    Is it exact what it is? Maybe you can try to “trim()” it to see the result.

    Also something you may have a try:
    1. Try a path without space.
    2. Change file permission to 777 and try it again.


    @ddliu – I can’t believe I didn’t recognize that… it looks like it was JUST as simple as an extra space at the end of my file name… So the file name was something like this:

    ‘Flip Flops.png ‘

    Once I did the trim(), it fixed it. Thank you!

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.