SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Unlink producing Error and not deleting intended file

    Hi,

    I am getting this Error message when trying to delete image files via the Unlink function:


    Warning: unlink() [function.unlink]: http does not allow unlinking in /var/www/html/anoox.com/inc/db_news.php on line 269

    But I am able to delete image files via Unlink function Ok from other Php programs.

    Note, only different between the db_news.php where the Unlink function produces Error and other Php files via where the Unlink function is working Ok is that db_news.php is an included file, which means it is being
    loaded via include into another Php file which is then calling a function in db_news.php which function
    has the job of deleting desiganted files via Unlink.

    Thanks for your help.

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    It's either a permissions issue on the file you want to delete or you have the incorrect path to the file in the unlink statement.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I totally suspect on the path of deleting file that you have given to the unlink function. It does not support URL paths before PHP 5 but supports URLs after 5.0 with some URL warppers. Can we see the code and also let us know the path & name of the file that you have passed to unlink function?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raju Gautam View Post
    I totally suspect on the path of deleting file that you have given to the unlink function. It does not support URL paths before PHP 5 but supports URLs after 5.0 with some URL warppers. Can we see the code and also let us know the path & name of the file that you have passed to unlink function?
    Here is the function in the included file which has the job of deleting given filenames:

    function delete_fotos ($article_id, $user_id)
    {

    //1st physically delete the images b4 deleting them from the DB
    $sql_get_images = "SELECT number, type FROM user_images WHERE article_id = $article_id";
    $query_get_images = mysql_query($sql_get_images) or die(mysql_error());
    if (mysql_num_rows($query_get_images) > 0) {

    while ($result_get_images = mysql_fetch_array($query_get_images)) {

    $number = $result_get_images['number'];
    $type = $result_get_images['type'];

    $file_name = $user_id . '_' . $article_id . '_foto' . $number . '.' . $type;
    $target_path = 'http://www.anoox.com/news/user_images/' . $file_name;

    unlink($target_path);

    }//CLOSES While Loop
    }//CLOSES if (mysql_num_rows($query_get_images) > 0)

    $sql_remove_fotos = "DELETE FROM user_images WHERE article_id = $article_id";
    mysql_query($sql_remove_fotos) or die(mysql_error());

    }

    FYI, here is the actual URL to a typical image file:
    http://www.anoox.com/news/user_image...3542_foto2.jpg

    As you can see the path as given to the Unlink function is correct!

    ThanX
    Dean

    Anoox search engine volunteer

    www.anoox.com

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you read my post above clearly that the function unlink does not support http URLs. You have used 'http://www.anoox.com/news/user_images/' . $file_name;. You need to use /path/to/the/image/image.jpg instead.

    Does this make sense?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Actually I already solved the problem based on your past message that Php does not support absolute URLs by switching to relative URL.
    ThanX.
    Now I have to update all the codes where the delete_foto function is being called to give it the path modifier to the relative path. Joy

    Quote Originally Posted by Raju Gautam View Post
    Did you read my post above clearly that the function unlink does not support http URLs. You have used 'http://www.anoox.com/news/user_images/' . $file_name;. You need to use /path/to/the/image/image.jpg instead.

    Does this make sense?

    Anoox search engine volunteer

    www.anoox.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •