Welcome Guest, Not a member yet? Register   Sign In
[ SOLVED ] Unlink problem
#1

[eluser]GreenDude[/eluser]
I tried to use the unlink() function but I get an error I don't understand.

Code:
$filestring = base_url().'uploads/'.$row->filename.$row->ext;
unlink ( $filestring );

Quote:A PHP Error was encountered

Severity: Warning

Message: unlink() [function.unlink]: http does not allow unlinking

Filename: controllers/face.php

Line Number: 109

Any ideas why? I am aware that this might be a newbie-ish problem :)
#2

[eluser]xwero[/eluser]
you need the full path for the unlink function. I've added a constant to the index.php for these situations
Code:
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('FCPATH', __FILE__);
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('PUBPATH',str_replace(SELF,'',FCPATH)); // added
then you can do
Code:
$filestring = PUBPATH.'uploads/'.$row->filename.$row->ext;
#3

[eluser]GreenDude[/eluser]
works! Big Grin

Thanks a lot for the quick reply
#4

[eluser]CIfan1000[/eluser]
PS
I had the same problem and found a different solution than the above.

See http://ellislab.com/forums/viewthread/45478/

The path simply needs to be relative to the directory that contains the CI index.php file.

Code:
// Delete the image of the harddisk:
        
            // Create path of image:
            // NOTE: The path MUST be relative, not absolute (eg NOT http//:....)
                // and it is relative to the CodeIgniter root directory
            $ImagePathAndName = "images/".$ImageName;
            //echo $ImagePathAndName;
            
            // Delete file off of harddisk using PHP command unlink:
            $do = unlink($ImagePathAndName);
            
            if($do == "1")
                {
                    echo "The file was deleted successfully.";
                }
                else
                    {
                        echo "There was an error trying to delete the file.";
                    }

This worked just fine.
#5

[eluser]hugle[/eluser]
[quote author="xwero" date="1201726096"]you need the full path for the unlink function. I've added a constant to the index.php for these situations
Code:
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('FCPATH', __FILE__);
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('PUBPATH',str_replace(SELF,'',FCPATH)); // added
then you can do
Code:
$filestring = PUBPATH.'uploads/'.$row->filename.$row->ext;
[/quote]


Nice sollution, thank you.
#6

[eluser]babelawra[/eluser]
Hi, yeah old topic but effective.

xwero's solution is cleaner but i used what CIfan1000 suggested and works perfectly Smile

Thanks
#7

[eluser]Cesar Kohl[/eluser]
"The path simply needs to be relative to the directory that contains the CI index.php file."

That's perfect! Thanks Cifan1000
#8

[eluser]InsiteFX[/eluser]
You can also do it this way
Code:
$filestring = APPPATH.'../uploads/'.$filename;
unlink ($filestring);




Theme © iAndrew 2016 - Forum software by © MyBB