Forums

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
    Posts
  • #33540
    nchipping
    Member

    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:

    unlink(str_replace(“http://www.url.com/”,””,$films));

    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:

    unlink(upload/uploads/images/VZB-idea.png);

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

    unlink($_SERVER . str_replace(“http://www.url.com/”,””,$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.

    #83543
    nchipping
    Member

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

    #83585
    ddliu
    Member

    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("http://www.url.com","",$films);

    echo $file_path;
    echo '
    ';
    var_dump(file_exists($file_path));

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

    #83599
    nchipping
    Member

    @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/mysite.net/upload/uploads/images/Flip Flops.png
    ) [function.unlink]: No such file or directory in /home/syxbit/public_html/mysite.net/edit_videos.php on line 27

    The output of:

    echo $_SERVER . str_replace("http://www.mysite.net","",$films);

    is exactly the path in the unlink.

    Any other ideas?

    #83615
    ddliu
    Member

    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/mysite.net/upload/uploads/images/Flip Flops.png
    HERE IS A NEW LINE?
    )

    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.

    #83619
    nchipping
    Member

    @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.