#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    84
    Rep Power
    15
    I can use php to execute the cp command to copy an image file into a directory.

    Now I want to delete images in that directory if they are not named "picturelink.gif" when an entry with a corresponding id is deleted.

    Below is the code I am using which doesn't seem to be working when it comes to deleteing the file. The directory has the correct permissions for read/write access.

    $query = "DELETE FROM $userstable WHERE id ='$id' ";

    if($picture != "picturelink.gif")
    {
    exec("rm $picture /virtualhosts/capefearantiques.com/www/pictures/$picture");
    }

    Any help would be greatly appreciated.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    63
    Rep Power
    15
    See PHP manual

    http://www.php.net/manual/function.unlink.php

    You could use

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    unlink("/virtualhosts/capefearantiques.com/www/pictures/$picture");
    [/code]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    84
    Rep Power
    15
    Error message....

    As a result I get:

    Warning: Unlink failed (Operation not permitted) in /virtualhosts/capefearantiques.com/www/catalogadmin/catalogadmindel.php3 on line 25.

    The directory has all permissions enabled for everyone.

    Any more suggestions?

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by chris22:
    See PHP manual

    http://www.php.net/manual/function.unlink.php

    You could use

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    unlink("/virtualhosts/capefearantiques.com/www/pictures/$picture");
    [/code]
    [/quote]

  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    exec("rm -f $file.$exn");

    the -f switch turns off conformation which exec can not handle - just remember how dangerous this could be - especially with user uploaded files!

    unlink($path/$file); will work if permissions are set correctly

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    84
    Rep Power
    15
    I still get the same error:
    Unlink failed (Operation not permitted) in /virtualhosts/capefearantiques.com/www/catalogadmin/catalogadmindel.php3 on line 25


    Line 25 looks like this:

    unlink("/virtualhosts/capefearantiques.com/www/pictures/$picture");

    I have the directory "pictures" chmoded to 777
    read all, write all, execute all.

    Still no luck. It's driving me mad.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by firepages:
    exec("rm -f $file.$exn");

    the -f switch turns off conformation which exec can not handle - just remember how dangerous this could be - especially with user uploaded files!

    unlink($path/$file); will work if permissions are set correctly
    [/quote]

  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    i'd like U to confirm a few things.

    1) a filename in the specified directory is assigned to $picture?
    2) the file actually exists to be unlinked or removed?

    if there is no file to be deleted, then obviously U'll get an error message.
  12. #7
  13. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>I have the directory "pictures" chmoded to 777
    >>read all, write all, execute all

    If Apache is run as nobody, right, that directory needs to be 757 or 777 should do fine. If Apache is run as another user, that directory permission should be 775, again, 777 should do fine.

    Your problem is the permission of the image. You need to chmod it either 646 or 664 or 666.

    More references:
    646 -> -rw-r--rw-
    664 -> -rw-rw-r--
    666 -> -rw-rw-rw-

    >>I can use php to execute the cp command to copy an image file into a directory

    Yes, as long as you have READ permission to that image and WRITE permission to the directory you wish to write to.

    You can cp -Rp /etc/* /path/to/hack
    Given Apache user "nobody" has permission to WRITE to hack dir 757 (drwxr-xrwx) and whatever file or dir in /etc needs to be READABLE.

    It doesn't matter whether you wish to use "rm -rf /path/to/image_file" or unlink, it's all about UNIX permission and has nothing to do with PHP.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    84
    Rep Power
    15
    Actually, I ftp'd into the pictures directory, set the permissions on the picture to 777 and then executed the unlink command.
    Still an error. According to my host, all commands are enabled for php.

    The one thing I noticed is that when I chmoded using the 0666 command in php like this:

    if($picture != "picturelink.gif")
    {
    chmod ("/virtualhosts/capefearantiques.com/www/pictures/$picture", 0666);
    }

    The actual "pictures" directory was chomoded and not the picture. Am I screwing up somewhere in my syntax? If so how do I get it to chmod the file instead of the darn directory?


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by freebsd:
    >>I have the directory "pictures" chmoded to 777
    >>read all, write all, execute all

    If Apache is run as nobody, right, that directory needs to be 757 or 777 should do fine. If Apache is run as another user, that directory permission should be 775, again, 777 should do fine.

    Your problem is the permission of the image. You need to chmod it either 646 or 664 or 666.

    More references:
    646 -> -rw-r--rw-
    664 -> -rw-rw-r--
    666 -> -rw-rw-rw-

    >>I can use php to execute the cp command to copy an image file into a directory

    Yes, as long as you have READ permission to that image and WRITE permission to the directory you wish to write to.

    You can cp -Rp /etc/* /path/to/hack
    Given Apache user "nobody" has permission to WRITE to hack dir 757 (drwxr-xrwx) and whatever file or dir in /etc needs to be READABLE.

    It doesn't matter whether you wish to use "rm -rf /path/to/image_file" or unlink, it's all about UNIX permission and has nothing to do with PHP.
    [/quote]

  16. #9
  17. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    You still haven't provided me with what apache user runs as and the other info.
    Anyway, your images need to be chmod'ed 646 or 664 or 666 depending on what Apache user runs as I mentioned previously.
    The Directory where the images reside needs to be chmod'ed 757 or 775 or 777.

    You now need to ftp to your account and chmod those manually.
    Next, adding "umask" to your php script. Set the "umask" to be 002 if Apache is run as another user (the same group). If it's "nobody", set it to 020. Check the PHP manual to find out more about "umask".

    If the existing images is NOT chmod'ed 666, you can't use unlink nor rm -rf. For any images in the future, the umask and proper chmod should solve the problem.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    84
    Rep Power
    15
    The problem seems to be a result of the
    if($picture != "picturelink.gif") statement as when I get rid of that and just put the unlink command everything works....
    Is there a problem with my syntax above?

    I really appreciate all the help I have gotten from everyone here.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by freebsd:
    You still haven't provided me with what apache user runs as and the other info.
    Anyway, your images need to be chmod'ed 646 or 664 or 666 depending on what Apache user runs as I mentioned previously.
    The Directory where the images reside needs to be chmod'ed 757 or 775 or 777.

    You now need to ftp to your account and chmod those manually.
    Next, adding "umask" to your php script. Set the "umask" to be 002 if Apache is run as another user (the same group). If it's "nobody", set it to 020. Check the PHP manual to find out more about "umask".

    If the existing images is NOT chmod'ed 666, you can't use unlink nor rm -rf. For any images in the future, the umask and proper chmod should solve the problem.
    [/quote]

  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    84
    Rep Power
    15
    Ok.. I have figured it out. The problem was had something to do with php not knowing what the value of $picture was. Therefore it cold not compare the "picture" column in the database to a value because it didn't have any way of knowing what that value was (if that's not too confusing). so, what I had to do is run 2 queries on one page- the first queried the database and defined the value for $picture, the php command then took that value, compared it to the picturelink.gif value to see if it was different, and then if it was continued with the unlink command by deleting the value (or file name) associated with the data $picture. A second query then deleted the rest of the info that corresponded to that image from the database.
    wheeeewww.
    Again, thanks for everyone's help.

    Below is the code in cse anyone is interested:

    <?
    /* */

    /* declare some relevant variables */

    $hostname = "www..com";
    $username = "";
    $password = "";
    $dbName = "";
    /* MySQL table created to store the data */
    $userstable = "items";

    /* make connection to database */
    MYSQL_CONNECT($hostname,$username,$password) OR DIE("Unable to connect to database");

    @mysql_select_db("$dbName") or die("Unable to select database");

    $query1 = "SELECT * FROM $userstable";

    $result1 = MYSQL_QUERY($query1);

    $picture = mysql_result($result1,$i,"picture");

    umask(020);

    if($picture != "picturelink.gif")
    {
    unlink("/virtualhosts/capefearantiques.com/www/pictures/$picture");
    }

    /* delete information from table */
    $query = "DELETE FROM $userstable WHERE id ='$id' ";

    $result = MYSQL_QUERY($query);

    PRINT "Your information has been deleted from our database.";

    /* Close the database connection */
    MYSQL_CLOSE();
    ?>

    That's it. hopefully someone can benefit from it.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by jpluttme:
    The problem seems to be a result of the
    if($picture != "picturelink.gif") statement as when I get rid of that and just put the unlink command everything works....
    Is there a problem with my syntax above?

    I really appreciate all the help I have gotten from everyone here.

    [/quote]


IMN logo majestic logo threadwatch logo seochat tools logo