Jump to content


Photo

unlink help


  • Please log in to reply
1 reply to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 04 May 2006 - 04:26 PM

hey guys,

I made this script where an admin can approve/decline user submitted pics but I ran into a snag.

here's part of the script

function delete($user_dat, $globalvars)
    {
        $split_imgname = explode('.', $_GET['delete']);
        
        if($split_imgname[1] == null)
        {
            echo "We shall have no directory deleting here.";
            
            $exitp = new template();
            $exitp->exitp($user_dat, $globalvars);
        }
        
        if(unlink($_GET['user'] . "/" . $_GET['delete']))
        {
            @unlink($_GET['user'] . "/thumbnails/" . $split_imgname[0] . ".gif");
            mysql_query("DELETE FROM vibe_img WHERE username = '" . $_GET['user'] . "' && image_name = '" . $_GET['delete'] . "'");
            
        } else {
            echo "Could not remove the image because of unknown errors. ";
            echo 'Click <a href="' . $_SERVER['PHP_SELF'] . '?admin=viewuploads">here</a> to go back.';
        }
    }
    
    function viewuploads($user_dat, $globalvars)
    {
        $sql = 'SELECT * FROM vibe_img WHERE status = "Pending Approval" ORDER BY img_date';
        $query = mysql_query($sql) or die('SQL Error <br>'.$sql.'<br>'.mysql_error());
    
        while($data = mysql_fetch_assoc($query))
        {
            $rem_array = array("-", ".", "!", " ");
            $js_functions = str_replace($rem_array, "", $data['image_name']);            
            $split_name = explode('.', $data['image_name']);
            
            echo '<script>
                                
                function del' . $js_functions. '()
                {
                    var delimgfinal = confirm("Are you sure you want to delete, ' . $data['image_name'] . '?")
                    if(delimgfinal == true)
                    {
                        window.location = "' . $_SERVER['PHP_SELF'] . '?admin=delete&delete=' . $data['image_name'] . '&user=' . $data['username'] . '"
                    } else {
                    
                    }
                }
                </script>';
            
            echo '<a href="users/' . $data['username'] . '/' . $data['image_name'] . '" target="_blank"><img src="users/' . $data['username'] . '/thumbnails/' . $split_name[0] . '.gif" border="0" /></a><br /><p></p>';
            echo '<input type="button" onclick="app' . $js_functions . '()" value="Approve" /> 
                <input type="button" onclick="del' . $js_functions . '()" value="Decline" /><br /><p></p>';
        }
        
    }

my problem is that it always gives me an error saying that the image file doesn't exist even though it does and it's looking in the right directory

here's the error I got

Warning: unlink(admin/Fish.jpg): No such file or directory

and it does that to whatever user I try to delete the pic except it says the member's username instead of admin

any ideas?

#2 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 04 May 2006 - 04:45 PM

nevermind found my own mistake, it was actually pointing at the root directory instead of where my script was




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users